Michael Roth wrote:
Yes, I have done: push, pop, top, nop, count, clear, isolate and binop.
All pretty easy, once I understand that Stack a b thing.
Now you are ready to write your monad tutorial. This is a standard rite
of passage (or should that be write a passage) for new Haskell
Michael Roth wrote:
Did you mean:
isolate :: Stack s1 a - Stack s2 a
isolate stack = Stack f where f xs = ( fst $ run stack [], xs)
Yes. What's slightly interesting is the way the types promise the
isolation: the Stack s1 action clearly can't be consuming any of the
[s2]
Hello list,
while trying to learn the secrets of monads, I decided to write a simply
monand for pure educational purpose. But it turned out that it isn't as
easy as I thought... I circumnavigate quite a number of hurdles but now
I reached a point where I'm at a loss. :-(
The source:
#!
Michael Roth wrote:
while trying to learn the secrets of monads, I decided to write a simply
monand for pure educational purpose. But it turned out that it isn't as
easy as I thought... I circumnavigate quite a number of hurdles but now
I reached a point where I'm at a loss. :-(
data
Michael Roth wrote:
Hello list,
while trying to learn the secrets of monads, I decided to write a simply
monand for pure educational purpose. But it turned out that it isn't as
easy as I thought... I circumnavigate quite a number of hurdles but now
I reached a point where I'm at a loss. :-(
data Stack a = Stack { run :: [a] - (a, [a]) }
[...skipped...]
But, I have simply no clue how to fix that. :-(
Can anybody give my a hint?
Yes. It's simply impossible. The Stack data type can't be turned into
a monad.
May be you can explain what do you want to do with this
On Mon, 7 Jan 2008, Miguel Mitrofanov wrote:
data Stack a = Stack { run :: [a] - (a, [a]) }
[...skipped...]
But, I have simply no clue how to fix that. :-(
Can anybody give my a hint?
Yes. It's simply impossible. The Stack data type can't be turned into
a monad.
What about using
Miguel Mitrofanov wrote:
Yes. It's simply impossible. The Stack data type can't be turned into
a monad.
Why not? Surely this is just a variation on the theme of a state monad?
Paul.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
On Mon, 2008-01-07 at 18:15 +0300, Miguel Mitrofanov wrote:
data Stack a = Stack { run :: [a] - (a, [a]) }
[...skipped...]
But, I have simply no clue how to fix that. :-(
Can anybody give my a hint?
Yes. It's simply impossible. The Stack data type can't be turned into
a monad.
On Mon, 2008-01-07 at 18:21 +, Paul Johnson wrote:
Miguel Mitrofanov wrote:
Yes. It's simply impossible. The Stack data type can't be turned into
a monad.
Why not? Surely this is just a variation on the theme of a state monad?
I somewhat explain in this reply:
Yes. It's simply impossible. The Stack data type can't be turned
into a monad.
Why not? Surely this is just a variation on the theme of a state
monad?
Because it can't be turned into a functor. You can't, given a
function a - b, construct a function Stack a - Stack b. On the
contrast,
Miguel Mitrofanov schrieb:
May be you can explain what do you want to do with this monad?
Pure educational purpose, just learning by doing.
What kind of code would you write if it would be such monad?
Useless stuff like:
s2 = do
push 11
push 17
count =
Jules Bean schrieb:
data Stack a b = Stack { run :: [a] - (b, [a]) }
Thank you, that does the trick.
The correct types for the other functions are:
push :: a - Stack a ()
pop :: Stack a a
top :: Stack a a
With those clues I think you will be able to write = and return more
What kind of code would you write if it would be such monad?
Useless stuff like:
s2 = do
push 11
push 17
count = push
binop (+)
binop (*)
pop
Then you should use something like
data Stack a = Stack {run :: [Integer] -
14 matches
Mail list logo