Re: [Haskell-cafe] Problem with own written monad

2008-01-09 Thread Paul Johnson
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

Re: [Haskell-cafe] Problem with own written monad

2008-01-08 Thread Jules Bean
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]

[Haskell-cafe] Problem with own written monad

2008-01-07 Thread Michael Roth
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: #!

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Tillmann Rendel
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

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Jules Bean
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. :-(

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Miguel Mitrofanov
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

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Henning Thielemann
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

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Paul Johnson
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

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Derek Elkins
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.

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Derek Elkins
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:

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Miguel Mitrofanov
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,

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Michael Roth
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 =

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Michael Roth
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

Re: [Haskell-cafe] Problem with own written monad

2008-01-07 Thread Miguel Mitrofanov
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] -