I see now that what I thought was happening wasn't happening at all.
> top (push 1 s1) gives me the top of the new Stack returned by PUSH. s1
> remains unchanged.
Thanks,
Michael
--- On Fri, 2/5/10, minh thu wrote:
From: minh thu
Subject: Re: [Haskell-cafe] Stack ADT?
To: &q
2010/2/5 michael rice
>
> Not using Stack for anything, just trying to understand how things can be
> done in Haskell.
>
> To that end...
>
> What's going on here? I'm not even calling function POP.
>
> Michael
>
> ==
>
> module Data.Stack (Stack, emptyStack, isEmptyStack, pus
> What's going on here? I'm not even calling function POP.
> *Data.Stack> let s2 = pop s1
> *Data.Stack> top s2
> *** Exception: Stack.hs:8:0-28: Non-exhaustive patterns in function pop
Haskell being a non strict language, does not evaluate pop s1 when you define
let s2 = pop s1.
but when you try
Stack.hs:8:0-28: Non-exhaustive patterns in function pop
>
> *Data.Stack>
>
>
>
>
> --- On *Fri, 2/5/10, Casey Hawthorne * wrote:
>
>
> From: Casey Hawthorne
> Subject: Re: [Haskell-cafe] Stack ADT?
> To: haskell-cafe@haskell.org
> Date: Friday, February 5, 2
; top (push 2 s1)
2
*Data.Stack> top (push 3 s1)
3
*Data.Stack> let s2 = pop s1
*Data.Stack> top s2
*** Exception: Stack.hs:8:0-28: Non-exhaustive patterns in function pop
*Data.Stack>
--- On Fri, 2/5/10, Casey Hawthorne wrote:
From: Casey Hawthorne
Subject: Re: [Haskell-ca
> "Casey" == Casey Hawthorne writes:
Casey> You could also implement stacks with mutable data structures,
Casey> e.g. STArray, etc.
Casey> What do you want to use a stack ADT for?
BTW, There is a Myers stack in Edison.
Disclaimer - I don't know what a Myers stack is.
--
Colin
You could also implement stacks with mutable data structures, e.g.
STArray, etc.
What do you want to use a stack ADT for?
Usually stacks are discussed for pedagogical purposes but usually
recursion is used if you need a stack like operation.
--
Regards,
Casey
_
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 sta
On Feb 4, 2010, at 6:27 PM, michael rice wrote:
I haven't done much with modules so I'm guessing what you've
provided is the guts of StackImpl, to hide the implementation?
Right. In order to make the Stack type abstract, you can hide the
Stack data (that is, newtype) constructor and only e
Am Donnerstag 04 Februar 2010 23:18:34 schrieb Daniel Peebles:
> > data Stack a = EmptyStk | Stk a (Stack a)
>
> I find it amusing that the book defined a type that is exactly
> isomorphic to the standard list (EmptyStk === [] and Stk === (:)). I
> guess it's just for clarity?
Also type safety,
>
> data Stack a = EmptyStk | Stk a (Stack a)
I find it amusing that the book defined a type that is exactly isomorphic to
the standard list (EmptyStk === [] and Stk === (:)). I guess it's just for
clarity?
On Thu, Feb 4, 2010 at 12:29 PM, Casey Hawthorne wrote:
> On Thu, 4 Feb 2010 09:07:28
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
>
From "Algorithms: a functional programming approach"
Second edition
Fethi Rabhi
Guy Lapalme
To be more complete.
module Stack(Stack,push,pop,top,emptyStack,stackEm
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
>
From "Algorithms: a functional programming approach"
Second edition
Fethi Rabhi
Guy Lapalme
data Stack a= EmptyStk
ischer
Subject: Re: [Haskell-cafe] Stack ADT?
To: "haskell-cafe Cafe"
Date: Thursday, February 4, 2010, 12:16 PM
On Feb 4, 2010, at 6:07 PM, michael rice wrote:
> Can't find a Stack datatype on Hoogle? Where should I look?
Could not find one on Hackage either. Probably becau
On Feb 4, 2010, at 6:07 PM, michael rice wrote:
Can't find a Stack datatype on Hoogle? Where should I look?
Could not find one on Hackage either. Probably because its so easy to
handcraft your own:
newtype Stack a = Stack [a]
emptyStack = Stack []
isEmptyStack (Stack xs) = n
Can't find a Stack datatype on Hoogle? Where should I look?
Michael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
16 matches
Mail list logo