orzo 2017-01-28 21:45:31
they are part of the signature
Lokathor 2017-01-28 21:46:32
they are part of the signature, but they don't reprisent input and output types of a function, they reprisent limits on how a generic function can be turned into a concrete function
Lokathor 2017-01-28 21:46:55
you can't use fromIntegral on a String, because a String isn't in the "Integral" typeclass, so it doesn't satisfy "Integral a", for example
Lokathor 2017-01-28 21:47:51
compare with the "id" function
Lokathor 2017-01-28 21:47:52
:t id
lambdabot 2017-01-28 21:47:55
a -> a
Lokathor 2017-01-28 21:48:17
there's no constraint on the 'a', so you can pass in literally any type of value at all to the id function, and it will work
systadmin 2017-01-28 21:48:41
So if I do =>
systadmin 2017-01-28 21:48:55
There are certain types of values that can't be used?
Lokathor 2017-01-28 21:49:32
yes, the part before the => specifies the type classes that work for the generic types after the =>
Lokathor 2017-01-28 21:50:02
ghc will generally infer the most generic type possible for things that you write, but you can specity a more specific type if you want and it will use that instead
orzo 2017-01-28 21:50:14
this is a good way to think of it in the beginning, but it's not technically right. For example, Typable t => doesn't put any constraint on t
orzo 2017-01-28 21:51:02
your actually declaring that you are using some propery of the type
systadmin 2017-01-28 21:51:39
So (Num b,Integral a) can only use the type of value given to it? Which is Num and Integral
Lokathor 2017-01-28 21:52:41
systadmin, Num and Integral are type classes, so they're groups that a type can have an instance of or not. If a type has an instance of Num, then it can be used in a situation that calls for a "Num a" value
orzo 2017-01-28 21:52:41
no, Num is a collection of types, you can use any one of those to instantiate the type variable b
kadoban 2017-01-28 21:53:32
Examples of Num instances would be Int, Integer, Float, Double, etc.
systadmin 2017-01-28 21:57:25
So b and a can only use the type classes given to them?
mrkgnao 2017-01-28 21:57:31
why does this kind of thing not work?
mrkgnao 2017-01-28 21:57:40
> go :: ((b -> c), [(a, b)]) -> [(a, c)]
lambdabot 2017-01-28 21:57:44
error:
lambdabot 2017-01-28 21:57:44
• Variable not in scope: go :: (b1 -> c1, [(a1, b1)]) -> [(a1, c1)]
lambdabot 2017-01-28 21:57:44
• Perhaps you meant one of these:
mrkgnao 2017-01-28 21:57:55
> go (func,pairs) = map (second func) pairs
lambdabot 2017-01-28 21:57:57
lambdabot 2017-01-28 21:57:57
parse error on input '='
lambdabot 2017-01-28 21:57:57
Perhaps you need a 'let' in a 'do' block?
mrkgnao 2017-01-28 21:58:04
> go (func,pairs) = map (second func) pairs
lambdabot 2017-01-28 21:58:06
lambdabot 2017-01-28 21:58:06
parse error on input '='
lambdabot 2017-01-28 21:58:06
Perhaps you need a 'let' in a 'do' block?
mrkgnao 2017-01-28 21:58:08
> let go (func,pairs) = map (second func) pairs
lambdabot 2017-01-28 21:58:11
lambdabot 2017-01-28 21:58:11
not an expression: 'let go (func,pairs) = map (second func) pairs'
mrkgnao 2017-01-28 21:58:22
I am so ham-fingered
kadoban 2017-01-28 21:58:23
mrkgnao: lpaste.net please
Lokathor 2017-01-28 21:58:53
systadmin, the a and b values must be values of a type that has an instance of the typeclass specified
mrkgnao 2017-01-28 21:58:54
how do I define a function here? it's just that thing I need, lpaste would probably be overkill
Lokathor 2017-01-28 21:59:13
note that, for example, all Integral values are also Num values
Lokathor 2017-01-28 21:59:23
mrkgnao, nope, lpaste is just right for this :3
mrkgnao 2017-01-28 21:59:34
Lokathor: okay, sure
kadoban 2017-01-28 22:01:27
mrkgnao: For the record you can do @let with lambdabot
MarcelineVQ 2017-01-28 22:01:31
@let go :: ((b -> c), [(a, b)]) -> [(a, c)]; go (func,pairs) = map (second func) pairs
lambdabot 2017-01-28 22:01:32
Defined.
kadoban 2017-01-28 22:01:33
It's a bit tricky to get right though
systadmin 2017-01-28 22:01:37
So Num a must have an instance of the Num typeclass?
Lokathor 2017-01-28 22:02:20
systadmin, yes, whatever type becomes the "a" has to have an instance of the Num typeclass, or GHC will reject it
systadmin 2017-01-28 22:02:37
Oh, okay. TIL
mrkgnao 2017-01-28 22:05:01
kadoban: http://lpaste.net/5692610178797535232
systadmin 2017-01-28 22:05:20
So in (Num b, Integral a) => a -> b
mrkgnao 2017-01-28 22:05:33
now obviously that list can't be constructed because it doesn't have a proper type (unless you use Either for the second element of the pairs)
Wojciech_K 2017-01-28 22:05:40
Why `type fn = Int -> Int` gives error 'Malformed head of type or class declaration'?
systadmin 2017-01-28 22:05:54
a and b in `a -> b' should use the type class it is given?
mrkgnao 2017-01-28 22:05:59
Wojciech_K: type names must be capitalized
Wojciech_K 2017-01-28 22:06:05
ahh, right
Wojciech_K 2017-01-28 22:06:07
thx
mrkgnao 2017-01-28 22:06:13
@let type Fn = Int -> Int;
lambdabot 2017-01-28 22:06:15
Defined.
Lokathor 2017-01-28 22:06:40
systadmin, yes, exactly
systadmin 2017-01-28 22:06:54
Which is what `=>` does?
mrkgnao 2017-01-28 22:07:36
but shouldn't there be ... some ... way to do it? with something like [forall a. a] (although this looks like a spectacularly bad idea because, well, this gives you heterogenous lists)
orzo 2017-01-28 22:07:50
ghc could probably do better than "malformed head" for a lowercased type name
mrkgnao 2017-01-28 22:08:29
I am ending up with a homogeneous list in the end, though. Can this be done without impredicative polymorphism, whatever that is?
Wizek_ 2017-01-28 22:08:36
@pl @pl (\x -> x & _1 .~ x^._2)
lambdabot 2017-01-28 22:08:36
(line 1, column 1):
lambdabot 2017-01-28 22:08:36
unexpected "@"
lambdabot 2017-01-28 22:08:36
expecting white space, "()", natural, identifier, lambda abstraction or expression
Lokathor 2017-01-28 22:08:54
systadmin, yes, the => is just a different kind of arrow because the normal -> arrow means something else
Wizek_ 2017-01-28 22:09:05
@pl (\x -> x & _1 .~ x^._2)
lambdabot 2017-01-28 22:09:05
(line 1, column 12):
lambdabot 2017-01-28 22:09:05
unexpected "_"
lambdabot 2017-01-28 22:09:05
expecting space or simple term
mrkgnao 2017-01-28 22:10:05
kadoban: Lokathor: I fixed an error in the lpaste. Mind looking at it?
mrkgnao 2017-01-28 22:10:12
okay, that came off wrong
kadoban 2017-01-28 22:10:51
I don't personally know a way to do that
Lokathor 2017-01-28 22:11:32
mrkgnao, if you don't know what signature you want, you can usually try leaving a signature off of xs entirely, getting a thing that loads into ghci, and then just using :t on it
kadoban 2017-01-28 22:11:58
Except that's not exactly going to help here, is it?
mrkgnao 2017-01-28 22:12:03
Lokathor: I *know* that xs can't be constructed in the obvious way.
Lokathor 2017-01-28 22:12:49
yes, it's quite an odd value for sure
mrkgnao 2017-01-28 22:13:10
I was just trying to refactor a bunch of a = map a1 a2; b = map b1 b2; bindings when I ran into this problem.
mrkgnao 2017-01-28 22:13:21
(Although one entirely of my construction, for sure.)
mrkgnao 2017-01-28 22:13:46
can impredicative polymorphism allow you to construct something like [2,"a"] :: [forall a. a]?
mrkgnao 2017-01-28 22:13:57
@let xs :: [forall a. a];
lambdabot 2017-01-28 22:13:58
Parse failed: Parse error: ]
mrkgnao 2017-01-28 22:14:09
@let xs :: [a];
lambdabot 2017-01-28 22:14:11
.L.hs:162:1: error:
lambdabot 2017-01-28 22:14:11
The type signature for 'xs' lacks an accompanying binding
mrkgnao 2017-01-28 22:15:24
I like how trying stupid things in Haskell is a ticket down $TYPE_THEORY_RABBIT_HOLE. :)
orzo 2017-01-28 22:21:49
mrkgnao: i think i have what you're looking for
systadmin 2017-01-28 22:22:48
I wanna code a combinations calculator
orzo 2017-01-28 22:22:54
mrkgnao: http://lpaste.net/5692610178797535232
Lokathor 2017-01-28 22:23:13
systadmin, what do you mean "combinations"?
systadmin 2017-01-28 22:23:30
Lokathor: it's a math thing
systadmin 2017-01-28 22:24:06
n! / ((n - r)! * r!)
Omnic 2017-01-28 22:29:10
whenever i hear the term "ADTs" that security company comes to mind
Omnic 2017-01-28 22:29:14
ok tahts all
orzo 2017-01-28 22:29:34
what would you prefer i call them
orzo 2017-01-28 22:29:48
never liked the name either
MarcelineVQ 2017-01-28 22:29:51
Aflacs
orzo 2017-01-28 22:29:54
heh
Omnic 2017-01-28 22:30:19
i don't really mind the name, just every time that's the first thing i think haha
Omnic 2017-01-28 22:30:30
probably b/c my grandparents had an adt alarm system
Omnic 2017-01-28 22:30:31
anyways
orzo 2017-01-28 22:30:42
i usually say "data structures" if i'm speaking outloud
orzo 2017-01-28 22:31:10
abstract seems a silly modifier
systadmin 2017-01-28 22:31:44
What's everyone up to?
MarcelineVQ 2017-01-28 22:32:03
the a is for algebraic
orzo 2017-01-28 22:32:21
oh, well okay
MarcelineVQ 2017-01-28 22:32:46
in our case because they define sums and products of types
systadmin 2017-01-28 22:33:31
How can I write a function that repeats a given string exactly n times?
orzo 2017-01-28 22:33:41
replicate n "given string"
cocreature 2017-01-28 22:34:08
systadmin: do you want to implement the function itself or are you ok just using a library function?
MarcelineVQ 2017-01-28 22:34:12
usually recursion with a value that ticks down each recurse that tracks what step you're on
cocreature 2017-01-28 22:34:14
in the latter case orzo has given you the solution
systadmin 2017-01-28 22:34:27
cocreature: whicher is easier
cocreature 2017-01-28 22:34:38
systadmin: then just use replicate :)
orzo 2017-01-28 22:34:45
we have such a tiny prelude
systadmin 2017-01-28 22:34:57
How can I set replicate to keep repeating the string for a given number of times?
cocreature 2017-01-28 22:35:05
:t replicate
orzo 2017-01-28 22:35:06
if people aren't memorizing it anyway, i vote we expand
lambdabot 2017-01-28 22:35:07
Int -> a -> [a]
cocreature 2017-01-28 22:35:14
the first argument is the number of repetitions
cocreature 2017-01-28 22:35:20
> replicate 3 "meh"
lambdabot 2017-01-28 22:35:23
["meh","meh","meh"]
cocreature 2017-01-28 22:35:38
if you want a single string you can combine that with concat
systadmin 2017-01-28 22:35:39
I'm just trying to solve this Kata https://www.codewars.com/kata/57a0e5c372292dd76d000d7e/train/haskell
cocreature 2017-01-28 22:35:44
> concat (replicate 3 "meh")
lambdabot 2017-01-28 22:35:47
"mehmehmeh"
MarcelineVQ 2017-01-28 22:36:39
that looks an awwwful lot like an exercise designed to make you think of and write a solution yourself instead of just inserting a library function :>
orzo 2017-01-28 22:37:05
naw
orzo 2017-01-28 22:37:13
he just has to adapt the library functions
orzo 2017-01-28 22:37:22
theres none of exactly the right type
cocreature 2017-01-28 22:37:25
if in doubt, just do it both ways :)
orzo 2017-01-28 22:37:31
:t replicate
lambdabot 2017-01-28 22:37:34
Int -> a -> [a]
orzo 2017-01-28 22:37:48
he needs (Int,String) -> String
orzo 2017-01-28 22:38:22
concat might prove useful
systadmin 2017-01-28 22:38:56
Should I remove the "" in: repeatStr n str = ""?
orzo 2017-01-28 22:40:50
well, your first case is repeat n "" = "". After that, you just need to write a case to match all possible strings
orzo 2017-01-28 22:41:06
i mean, one case for each string
orzo 2017-01-28 22:41:09
:D
orzo 2017-01-28 22:41:19
it's a long program
cocreature 2017-01-28 22:41:22
orzo: I don't think it really wants you to have that type. it looks like the question is just the same for all languages
orzo 2017-01-28 22:43:20
repeatStr n s = [1..n] >> s
orzo 2017-01-28 22:43:24
heh