[Haskell-beginners] Type classes and synonyms

Daniel Fischer daniel.is.fischer at web.de
Sat Nov 21 15:51:42 EST 2009


Am Samstag 21 November 2009 21:33:28 schrieb Philip Scott:
> Hi ho,
>
> > In general, however, you just need practice.  Go code! =)
>
> Righto, I am getting stuck in with that. One last question; I've been
> trying to read up on Arrows and my mind is being boggled. Via experiment, I
> have worked out what 'second' was doing (the documentation is useless
> unless you already understand a lot of stuff I clearly don't)
>
> For the other newbies, 'second' takes a function and a tuple, it applies
> the function to the second thing in your tuple and returns a tuple with the
> first
>
> value unchanged, and the result of applying 'f' to the second:
> >  second (\x -> "fish") (10,20)
>
> (10,"fish")
>
> What I am struggling to understand is what on earth the type signature means:
> :t second
>
> second :: (Arrow a) => a b c -> a (d, b) (d, c)
>
> How can (\x -> "fish") be an 'a b c' when it really looks like this:
> :t (\x->"fish")
> (\x->"fish") :: t -> [Char]

a is a type variable (restricted to be a member of the Arrow class).
Now the type ghci reports for (\x -> "fish") is printed in infix form, in prefix form, it 
reads

:t (\x -> "fish")
(\x -> "fish") :: (->) t [Char]

so we find

a = (->)
b = t
c = [Char]

and you're using the most widespread instance of Arrow, (->).

Arrows are a generalisation of functions.

Until you're more familiar with Arrows, I suggest replacing any
(Arrow a) with (->) in the type signatures to understand what things mean in the familiar 
case.

Next in line would probably be Kleisli arrows (Monad m => a -> m b; it's wrapped in a 
newtype for Control.Arrow), break at any level of abstraction you want and return later.

>
> And I am pretty sure I never made any Arrpws...

There are a few others have made for you to use :)

>
> I feel I am on the verge of understanding something deep and fundamentally
> philosophical about the typesystem but I can't quite bend my mind around to
> it
>
> :)
>
> All the best,
>
> Philip



More information about the Beginners mailing list