[Haskell-cafe] Confused about type seen in the wild

Kim-Ee Yeoh ky3 at atamo.com
Thu Apr 10 17:45:48 UTC 2014


On Fri, Apr 11, 2014 at 12:28 AM, Jason Dagit <dagitj at gmail.com> wrote:

> It seems to be an issue with giving everything on a single line:
>
> Prelude λ> let whee x = x == x && null (show x) :: Show a => Eq a => a =>
> Bool
>
> <interactive>:2:14:
>     Couldn't match expected type `a -> Bool' with actual type `Bool'
>     In the expression:
>         x == x && null (show x) :: Show a => Eq a => a => Bool
>     In an equation for `whee':
>         whee x = x == x && null (show x) :: Show a => Eq a => a => Bool
>

As the error message indicates, the (:: type) is being applied to the open
term: x == x && null (show x), and not to the function whee.

To do this single-line def properly, I think you need -XScopedTypeVariables:

    let whee (x :: a) = x == x && null (show x) :: Show a => Eq a => Bool



> I see now to make it work as a one liner I could do it this way:
> Prelude λ> :t (\x -> x == x && null (show x)) :: Show a => Eq a => a =>
> Bool
> (\x -> x == x && null (show x)) :: Show a => Eq a => a => Bool
>   :: (Eq a, Show a) => a -> Bool
>

And to recover the named binding:

    let whee = (\x -> x == x && null (show x)) :: Show a => Eq a => a =>
Bool


-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140411/7c9f1684/attachment.html>


More information about the Haskell-Cafe mailing list