[Haskell-beginners] Programming with Arrows

Michael Baker michaeltbaker at gmail.com
Fri Mar 22 22:39:07 CET 2013


I'm reading through http://www.cse.chalmers.se/~rjmh/afp-arrows.pdf

I was following it up until this example in the section about flip-flops:

class Arrow arr => ArrowLoop arr where
  loop :: arr (a,c) (b,c) -> arr a b

instance ArrowLoop (->) where
  loop f a = b
    where (b,c) = f (a,c)

Although I've never seen a function declaration like this, but I think I
get it. Because f :: (a, c) -> (b, c) then then loop f :: ((a, c) -> (b,
c)) -> (a -> b) which is the same as  ((a, c) -> (b, c)) -> a -> b.

However, I don't see where the c comes from in f (a,c). Is this a mistake
or am I missing something? A friend of mine realized that this is just a
recursive definition so f (a, c) == f (a, snd $ f (a, snd $ f (a, ...))). I
don't really understand this definition. I can see how it compiles, but I
don't see how it would ever produce a legitimate value. Do I have to assume
that f never evaluates the second element in the pair and just passes it
through?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130322/65e8448f/attachment.htm>


More information about the Beginners mailing list