Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How to understand arrows!

Name: Ponster Menis !Ep8pui8Vw2 2007-03-17 10:59 ID:cyRS7xdF

Allow me to translate these function definitions into what they really are!

(>>>) :: a b c -> a c d -> a b d
  (>>>) :: (b -> c) -> (c -> d) -> (b -> d)

first :: a b c -> a (b, d) (c, d)
  first :: (b -> c) -> ((b, d) -> (c, d))


Yes, functions are arrows, that's why this works!

Knowing this is really good when you are doing random numbers:
random = first (\ n -> ...) . next
Look up the specifications and you'll see that random (in the class Random) should take a RandomGen and return (x, g) where x is the random value and g is the generator.  next returns a similar pair with an int and the new generator that should be returned.

It's magic I'm telling you!

Name: Anonymous 2007-03-17 14:42 ID:mZahUIZq

Forced arbitrary of syntax, thread over.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List