[Haskell-cafe] What's the problem with iota's type signature?
Lee Duhem
lee.duhem at gmail.com
Wed May 27 23:22:11 EDT 2009
On Thu, May 28, 2009 at 10:33 AM, michael rice <nowgate at yahoo.com> wrote:
> Still exploring monads. I don't understand why the type signature for double
> is OK, but not the one for iota.
>
> Michael
>
> =================
>
> --double :: (Int a) => a -> Maybe b
> --double x = Just (x + x)
Prelude> let double x = Just $ x + x
Prelude> Just 2 >>= double
Just 4
You can define double as
double x = return $ x + x
Prelude> let double x = return $ x + x
Prelude> Just 2 >>= double
Just 4
>
> iota :: (Int a) => a -> [b]
> iota n = [1..n]
>
> --usage: [3,4,5] >>= iota
> --should produce [1,2,3,1,2,3,4,1,2,3,4,5]
I did.
Prelude> let iota n = [1..n]
Prelude> [3,4,5] >>= iota
[1,2,3,1,2,3,4,1,2,3,4,5]
lee
More information about the Haskell-Cafe
mailing list