On 10 May 2009, at 04:00, Cory Knapp wrote:
... There have been 12 replies to this question, all of which say
the same thing.
Brandon's one was different. And incorrect, which shows that this
question isn't completely obvious.
I'm glad we're so happy to help, but does
Just 3 = return
Hi Cory,
Cory Knapp wrote:
... There have been 12 replies to this question, all of which say the
same thing. I'm glad we're so happy to help, but does
Just 3 = return . (+1)
Need to be explained by 12 different people?
maybe eleven others have already pointed that out by now, but as far
Am Sonntag 10 Mai 2009 02:00:29 schrieb Cory Knapp:
... There have been 12 replies to this question, all of which say the
same thing. I'm glad we're so happy to help, but does
Just 3 = return . (+1)
Need to be explained by 12 different people?
fmap (trying to++) $ Just help -- :D
Cory
Why doesn't this work?
Michael
data Maybe a = Nothing | Just a
instance Monad Maybe where
return = Just
fail = Nothing
Nothing = f = Nothing
(Just x) = f = f x
instance MonadPlus Maybe where
mzero = Nothing
Nothing
Because you're looking for:
Just 3 = return . (+1)
or more simply
Just 3 = Just . (+1)
or more generally:
return 3 = return . (+1)
The second argument of (=) is supposed to be of type (Monad m = a
- m b) but (+1) ishe of type (Num a = a - a). Wre is the monad in
that?
Thomas
On Sat, May 9,
I think you're looking for fmap/liftM here. The type of = is:
(=) :: (Monad m) = m a - (a - m b) - m b
so it's trying to make your function (1+) return m b, which in this
case should be a Maybe. Clearly, (1+) doesn't return a Maybe, so it
breaks. Another options is to do return . (1+) to lift
On Sat, 9 May 2009, michael rice wrote:
Prelude Just 3 = (1+)
fmap (1+) (Just 3)
or
Just 3 = return . (1+)
or, with consistent order of functions
return . (1+) = Just 3
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
Hi,
(1+) :: Num a = a - a
For the bind operator, you need something of type a - Maybe b on the
RHS, not simply a - a. You want one of these instead:
fmap (1+) (Just 3)
liftM (1+) (Just 3)
Alternatively, you may find it useful to define something like:
(*) = flip liftM
so that you can
On May 9, 2009, at 15:31 , michael rice wrote:
Prelude Just 3 = (1+)
interactive:1:0:
No instance for (Num (Maybe b))
arising from a use of `it' at interactive:1:0-14
Possible fix: add an instance declaration for (Num (Maybe b))
In the first argument of `print', namely `it'
michael rice wrote:
Prelude Just 3 = (1+)
Let's check the types.
Prelude :t (=)
(=) :: (Monad m) = m a - (a - m b) - m b
Prelude :t Just 3
Just 3 :: (Num t) = Maybe t
Prelude :t (1 +)
(1 +) :: (Num a) = a - a
Renaming the variables in the type of (1 +) gives:
(1 +) :: (Num
Hi,
Haskell expects the function with type (a - m b) in the right side of
(=),
but you put there function with type (a - a):
try:
:t (Just 3 =)
(Just 3 =) :: (Num a) = (a - Maybe b) - Maybe b
and:
:t (1+)
(1+) :: (Num a) = a - a
You should put (1+) into Maybe monad, just do return.(1+), so
On Sat, May 9, 2009 at 12:31 PM, michael rice nowg...@yahoo.com wrote:
Why doesn't this work?
Michael
data Maybe a = Nothing | Just a
instance Monad Maybe where
return = Just
fail = Nothing
Nothing = f = Nothing
(Just x) = f = f x
Hey Michael,
If you would look at the type of =, it would give
(=) :: (Monad m) = m a - (a - m b) - m b
and specifically in your case:
(=) :: Maybe a - (a - Maybe b) - Maybe b
You are applying Just 3 as first argument, which is correct, but then supply
a partially applied function (1+) which
Types.
(=) :: Monad m = m a - (a - m b) - m b
(1+) :: Num a = a - a
So, the typechecker deduces that 1) a is the same as m b, and 2)
a (and m b, therefore) must be of class Num
Now,
Just 3 :: Num t = Maybe t
and the typechecker learns from that that m a must be the same as
Maybe t,
Excerpts from michael rice's message of Sat May 09 14:31:20 -0500 2009:
Why doesn't this work?
Michael
data Maybe a = Nothing | Just a
instance Monad Maybe where
return = Just
fail = Nothing
Nothing = f = Nothing
(Just x) = f = f
Am Samstag 09 Mai 2009 21:31:20 schrieb michael rice:
Why doesn't this work?
Michael
[mich...@localhost ~]$ ghci
GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base
On 10 May 2009, at 00:30, Brandon S. Allbery KF8NH wrote:
On May 9, 2009, at 15:31 , michael rice wrote:
Prelude Just 3 = (1+)
That (a - m b) in the middle is what's failing to typecheck. The
error is a bit obtuse because ghci is trying hard to find a way to
do what you want, so it
On May 9, 2009, at 18:03 , Miguel Mitrofanov wrote:
On 10 May 2009, at 00:30, Brandon S. Allbery KF8NH wrote:
On May 9, 2009, at 15:31 , michael rice wrote:
Prelude Just 3 = (1+)
That (a - m b) in the middle is what's failing to typecheck. The
error is a bit obtuse because ghci is trying
On May 9, 2009, at 18:16 , Brandon S. Allbery KF8NH wrote:
That's the only way I can get the error he got; if it uses Maybe as
the monad then why is the Maybe on the *inside* in the error
message? Clearly it bound m to something else, and ((-) r) is the
only other one I can think of
... There have been 12 replies to this question, all of which say the
same thing. I'm glad we're so happy to help, but does
Just 3 = return . (+1)
Need to be explained by 12 different people?
fmap (trying to++) $ Just help -- :D
Cory
Why doesn't this work?
Michael
[mich...@localhost ~]$
20 matches
Mail list logo