fork download
  1. import Control.Applicative
  2. import Control.Monad (guard)
  3. import Control.Arrow ((&&&))
  4. import Data.List (unfoldr)
  5.  
  6. g = sum
  7. . unfoldr ( id &&& \x ->
  8. x`div`2 <$ guard(even x)
  9. <|> x*3 + 1 <$ guard( x/=1 )
  10. )
  11.  
  12. main = print $ g 201
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:8:23:
    Couldn't match expected type `Maybe (c0, a0)'
                with actual type `(c1, c'0)'
    Expected type: a0 -> Maybe (c0, a0)
      Actual type: a0 -> (c1, c'0)
    In the first argument of `unfoldr', namely
      `(id
        &&&
          \ x
            -> x `div` 2 <$ guard (even x) <|> x * 3 + 1 <$ guard (x /= 1))'
    In the second argument of `(.)', namely
      `unfoldr
         (id
          &&&
            \ x
              -> x `div` 2 <$ guard (even x) <|> x * 3 + 1 <$ guard (x /= 1))'
stdout

Standard output is empty