Loading ...
Sorry, an error occurred while loading the content.

158Re: [extremeperl] Book: Higher Order Perl

Expand Messages
  • Terrence Brannon
    Mar 29, 2005
      Terrence Brannon <bauhaus@...> writes:


      > And a monad ...
      >
      > Example:

      Here's a working example. My earlier example was borked.

      mydat = [1 .. 4]

      trans1 x = [x]
      trans2 x = [x, x +1]
      trans3 x = [x +5]

      trans4 :: Integer -> [Char]
      trans4 x = replicate (fromIntegral x) 'a' ++ [':']

      *Main> mydat >>= trans1
      [1,2,3,4]
      *Main> (>>=) mydat trans1
      [1,2,3,4]
      *Main> mydat >>= trans2
      [1,2,2,3,3,4,4,5]
      *Main> mydat >>= trans3
      [6,7,8,9]
      *Main> mydat >>= trans4
      "a:aa:aaa:aaaa:"
      *Main> mydat >>= trans1 >>= trans2 >>= trans3
      [6,7,7,8,8,9,9,10]
      *Main> mydat >>= trans1 >>= trans2 >>= trans3 >>= trans4
      "aaaaaa:aaaaaaa:aaaaaaa:aaaaaaaa:aaaaaaaa:aaaaaaaaa:aaaaaaaaa:aaaaaaaaaa:"
      *Main>

      --
      Carter's Compass: I know I'm on the right track when,
      by deleting something, I'm adding functionality.
    • Show all 58 messages in this topic