Reputation: 25
So I put this statement on my ghci
jkl x f y = f (map (+y) x)
And I got this out put back.
jkl :: Num b => [b] -> ([b] -> t) -> b -> t
But I'm confused when I read it. From my understanding jkl is type num that takes [b], [b] and t, and b. in the end it will output t. is that the right way to read it?
Upvotes: 2
Views: 377
Reputation: 80734
Whatever is between the double colon ::
and the fat arrow =>
is called constraints. In this case, you have one constraint: Num b
. This constraint demands that, whatever type b
turns out to be, it must be an instance of type class Num
.
After the fat arrow, you get types of function parameters, and at the very end type of its result.
Parameters:
[b]
- a list of values of type b
, whatever that is.[b] -> t
- a function that takes a list of b
and produces a single t
.b
- a single value of type b
.And finally, function result is t
.
Upvotes: 7
Reputation: 116139
jkl :: Num b => [b] -> ([b] -> t) -> b -> t
Whoever calls jkl
has to
b
and t
b
was chosen among numeric types (the Num b
constraint)[b]
(list of b
) as first argument[b] -> t
as second argument (i.e. taking [b]
and returning a t
)b
as third argumentt
back as a final resultUpvotes: 12