Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread michael rice
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

Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread minh thu
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

Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread Rahul Kapoor
> 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

Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread Andrew Wagner
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

Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread michael rice
; 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

Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread Colin Paul Adams
> "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

Re: [Haskell-cafe] Stack ADT?

2010-02-05 Thread Casey Hawthorne
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 _

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread Richard O'Keefe
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

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread Sebastian Fischer
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

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread Daniel Fischer
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,

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread 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? On Thu, Feb 4, 2010 at 12:29 PM, Casey Hawthorne wrote: > On Thu, 4 Feb 2010 09:07:28

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread Casey Hawthorne
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

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread Casey Hawthorne
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

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread michael rice
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

Re: [Haskell-cafe] Stack ADT?

2010-02-04 Thread Sebastian Fischer
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

[Haskell-cafe] Stack ADT?

2010-02-04 Thread michael rice
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