Reputation: 424
Quick question I'm unable to understand how and why the following type definition gets formulated
:t const
const :: a -> b -> a
:t id
id :: a -> a
:t (const id)
(const id) :: b -> a -> a
Doesn't the following actually resolve too a -> a -> b -> a
where a -> a
is feed inside of a -> b -> a
AKA (const(id _))
anyone mind explaining how this is actually being transformed?
Upvotes: 0
Views: 64
Reputation: 531265
const x :: b -> ??
, where ??
is the type of x
. In this case, x
is the function id
, which has type a -> a
. Thus, const id :: b -> (a -> a)
, and you can drop the parentheses because ->
is right-associative.
Upvotes: 2
Reputation: 10457
const :: a -> b -> a
id :: c -> c
const before applied with id
const :: (c->c) -> b -> (c->c)
const after applied id
const id :: b -> (c -> c)
const id :: b -> c -> c
No matter what you apply to const id
you get c -> c
Upvotes: 2