
4 Feb
2010
4 Feb
'10
8:43 p.m.
On Feb 5, 2010, at 6:38 AM, Casey Hawthorne wrote:
On Thu, 4 Feb 2010 09:07:28 -0800 (PST), you wrote:
Can't find a Stack datatype on Hoogle? Where should I look?
Michael module Stack(Stack,push,pop,top,emptyStack,stackEmpty) where ...
Or just use a list. A more Haskellish approach to stacks than using "pop" and "top" would be something like this: newtype Stack t = [t] emptyStack = Stack [] stackPush (Stack s) = Stack (x:s) viewStack (Stack []) = Nothing viewStack (Stack (top:rest)) = Just (top, Stack rest) Instead of if stackEmpty s then ... else ... top s ... pop s ... do case viewStack s of Nothing -> ... Just (top, rest) -> ... Note that none of the functions in this interface can fail.