[Haskell-beginners] Fwd: Re: Multiple letters between -> ->

Jeffrey Brown jeffbrown.the at gmail.com
Sat Nov 25 17:56:50 UTC 2017


I don't know if this is helpful, but I've abbreviated and elaborated on
what Francesco said.

> Original I thought a Signature like:
>
> f :: h a -> h a
>
> means that h is a higher kinded type just like in Type Classes ( for
instance f in Functor f).
>
> But I heard such a meaning is not allowed in normal Haskell functions.
What instead is the meaning of h a?

Let's take a concrete example:

Prelude> let f = fmap id
Prelude> :t f
f :: Functor f => f b -> f b
Prelude>

The (->) symbol goes between types (it takes one type to another), so f b
must be a type, and therefore f is a type constructor.

> f Maybe
>
> throws an Error

Maybe is a type constructor, not a value constructor. Functions in Haskell
can only take types. Value constructors are types; type constructors are
not.

> but what is h in:
>
> f :: h a -> ...
>
> is "h" a data constructor or a type constructor or a normal function?
What is j in
>
> f:: j k l -> ...
>
> and hwat is the difference between j and h?

h and j in those examples are both type constructors. One of them takes two
arguments, the other only takes one.

> But why I can call g with Just:
>
>
> let g :: h a b -> h a b; g a = a
>
> g Just
>
> but Just is a->Maybe a

Just has type "(->) a (Maybe a)", a.k.a. type "a -> Maybe a". (->) is a
two-argument type constructor.

On Sat, Nov 25, 2017 at 8:39 AM, Francesco Ariis <fa-ml at ariis.it> wrote:

> On Sat, Nov 25, 2017 at 04:19:04PM +0100, Marcus Manning wrote:
> > But why I can call g with Just:
> >
> >
> > let g :: h a b -> h a b; g a = a
> >
> > g Just
> >
> > but Just is a->Maybe a
>
> Because (->) is a type constructor itself, just with
> convenient infix syntax:
>
>     λ> :k (->)
>     (->) :: TYPE q -> TYPE r -> *
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>



-- 
Jeff Brown | Jeffrey Benjamin Brown
Website <https://msu.edu/~brown202/>   |   Facebook
<https://www.facebook.com/mejeff.younotjeff>   |   LinkedIn
<https://www.linkedin.com/in/jeffreybenjaminbrown>(spammy, so I often miss
messages here)   |   Github <https://github.com/jeffreybenjaminbrown>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171125/f37cec53/attachment-0001.html>


More information about the Beginners mailing list