What's the problem with iota's type signature?

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) 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]

On 28/05/2009 04:33, michael rice 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)
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]
iota is executed within the monad and as such must respect its law ?
------------------------------------------------------------------------
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Wed, May 27, 2009 at 7:33 PM, michael rice
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)
iota :: (Int a) => a -> [b] iota n = [1..n]
Int is not a class, and you are using it as such?
--usage: [3,4,5] >>= iota --should produce [1,2,3,1,2,3,4,1,2,3,4,5]
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Thu, May 28, 2009 at 10:33 AM, michael rice
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

michael rice wrote:
Still exploring monads. I don't understand why the type signature for double is OK,
It isn't. The |a| and |b| variables must unify: Prelude> :t \x -> Just (x+x) \x -> Just (x+x) :: (Num a) => a -> Maybe a Prelude> :t (\x -> Just (x+x)) :: Num a => a -> Maybe b <interactive>:1:13: Couldn't match expected type `b' against inferred type `a' `b' is a rigid type variable bound by the polymorphic type `forall a b. (Num a) => a -> Maybe b' at <interactive>:1:0 `a' is a rigid type variable bound by the polymorphic type `forall a b. (Num a) => a -> Maybe b' at <interactive>:1:0 In the first argument of `Just', namely `(x + x)' In the expression: Just (x + x)
but not the one for iota.
Again the |a| and |b| must unify. Also, Int isn't a type class (did you mean Num?) Also, the use of (..) requires the Enum class. Prelude> :t \n -> [1..n] \n -> [1..n] :: (Enum t, Num t) => t -> [t] Prelude> [3,4,5] >>= (\n -> [1..n]) [1,2,3,1,2,3,4,1,2,3,4,5] -- Live well, ~wren
participants (5)
-
David Leimbach
-
Lee Duhem
-
Lionel Barret de Nazaris
-
michael rice
-
wren ng thornton