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
> successfully!

Yes, this was the missing link. Because I thought "Stack a a" could be
abbreviated using "Stack a" I run into these problems. This was also the
cause that "push" echoed back the pushed value.


> There are some other interesting combinators to consider, like:
>
> isolate :: Stack b x -> Stack a x
> -- runs the computation with an empty stack, therefore
> -- guaranteeing it does more pushes than pops

Did you mean:

        isolate :: Stack s1 a -> Stack s2 a
        isolate stack = Stack f where f xs = ( fst $ run stack [], xs)

> and so on.

Yes, I have done: push, pop, top, nop, count, clear, isolate and binop.
All pretty easy, once I understand that "Stack a b" thing.



_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to