[Haskell-beginners] pattern match vs. pure function

Daniel Fischer daniel.is.fischer at web.de
Wed Oct 20 10:28:52 EDT 2010


On Wednesday 20 October 2010 16:04:41, Patrick LeBoutillier wrote:
>  Prelude> :t flip
>   flip :: (a -> b -> c) -> b -> a -> c
>   Prelude> :t id
>   id :: a -> a
>   Prelude> :t flip id
>   flip id :: b -> (b -> c) -> c
>
> How does one get the type of "flip id" by applying "flip" to "id"?

flip :: (a -> b -> c) -> b -> a -> c

id :: t -> t

So for flip id, we must unify (t -> t) with (a -> b -> c), which is, fully 
parenthesized, (a -> (b -> c)).

So t = a, as that's what appears left of the outermost (->).
Also, t = (b -> c), as that's what appears right of the outermost (->).

a = t = b -> c, so in

flip id,

id appears at the type (b -> c) -> (b -> c) and flip is used at the type

((b -> c) -> (b -> c)) -> b -> (b -> c) -> c

The first is eaten by flip, leaving

flip id :: b -> (b -> c) -> c

>
>
> Thanks,
>
> Patrick

HTH,
Daniel



More information about the Beginners mailing list