[Haskell-beginners] infinite type

Theodore Lief Gannon tanuki at gmail.com
Sun Jan 3 21:30:38 UTC 2016


On Sun, Jan 3, 2016 at 1:05 PM, Imants Cekusins <imantc at gmail.com> wrote:

> Here is composition signature:
>
> (.)
> <http://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html#v:.> ::
> (b -> c) -> (a -> b) -> a -> c
>
> It looks like it is applicable to functions with 1 arg. Sum expects 2
> args. I guess this explains why sum can not be passed to f
>
This isn't accurate, and it's useful to understand why. Every function in
Haskell has exactly one argument. Joel touched on this earlier. It's easier
to see if you add the implied parentheses to the type signatures:

    sum :: Num a => a -> (a -> a)
    f :: (a -> a) -> (a -> a)

To really drive it home, let's play with synonyms.

    type Endo' a = (a -> a)

Endo already exists as a newtype in Data.Monoid, thus Endo' here. Now:

    sum :: Num a => a -> Endo' a
    f :: Endo' a -> Endo' a
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160103/5be32480/attachment.html>


More information about the Beginners mailing list