[Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-21 Thread Gene A
Hi All, I got up this morning {after not much sleep} to find these very helpful suggestions/comments: from Scott Turner: {... See: http://www.haskell.org/hawiki/ExistentialTypes ...} From Bulat Ziganshin: {... you can read recent discussion on this in this topic, or look at http://haskell.org

Re: [Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-21 Thread Lennart Augustsson
I don't know exactly what types you have as base types in your implementation, but here's a small code fragment that of what I had in mind. data Value = D Double | S String | B Bool type Stack = [Value] -- Add top stack elements plus :: Stack -> Stack plus (D x : D y : vs) = D (x+y) : vs pl

Re: [Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-21 Thread Bulat Ziganshin
Hello Gene, Monday, August 21, 2006, 12:42:17 PM, you wrote: > being able to use +,* on any of the numeric types... but can you have > a list of type [Num] ?? I thought that it had to be the base types of > Int, Integer, Float, Double etc.. No? you can, using existentials: data Number = foral

Re: [Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-21 Thread Scott Turner
On 2006 August 21 Monday 04:42, Gene A wrote: > but can you have > a list of type [Num] ?? I thought that it had to be the base types of > Int, Integer, Float, Double  etc..  No? See http://www.haskell.org/hawiki/ExistentialTypes ___ Haskell-Cafe mailing

[Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-21 Thread Gene A
Lennart and all, On 8/19/06, Lennart Augustsson <[EMAIL PROTECTED]> wrote: There are much better ways than storing strings on the stack. Like using a data type with constructors for the different types that you can store. -- Lennart Off topic, but this is important info for me! O

[Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-19 Thread Lennart Augustsson
There are much better ways than storing strings on the stack. Like using a data type with constructors for the different types that you can store. -- Lennart On Aug 19, 2006, at 11:51 , Gene A wrote: Hi Lennart, This morning when I posted..it was about 2:30am and had been up a long t

[Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-19 Thread Gene A
Hi Lennart, This morning when I posted..it was about 2:30am and had been up a long time... bad habits.. I sent a message to Henk-Jan to that effect, but didn't send to the entire list.. anyway thanks to both for the followups... I still tend to sometimes do things the hard way in Haskell. Start

Re: [Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-19 Thread Lennart Augustsson
On Aug 19, 2006, at 05:14 , Henk-Jan van Tuyl wrote: [...] *Iteration> fromtoby 12 42 3 (flip (**) 0.33) fromtoby 12 42 3 (**0.33) And why approximate so much? fromtoby 12 42 3 (** (1/3)) ___ Haskell-Cafe mailing list Haskell-

Re: [Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-19 Thread Henk-Jan van Tuyl
On Sat, 19 Aug 2006 10:28:33 +0200, Gene A <[EMAIL PROTECTED]> wrote: *Iteration> fromtoby 1 12 2 (flip (^) 3) -- cubing of the base list above.. An easier way to write this: fromtoby 1 12 2 (^3) [...] *Iteration> fromtoby 12 42 3 (flip (**) 0.33) fromtoby 12 42 3 (**0.

[Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-19 Thread Gene A
Hi, Here is a little thing I came up with to simulate the construct "for x:= n1 to n2" and "for x:=n1 to n2 by n3" from purely imperative world to use in Haskell, I call the functions fromto and fromtoby.. they also take a function which consumes the x component and uses it in the computation.

[Haskell-cafe] Re: iterative algorithms: how to do it in Haskell?

2006-08-16 Thread Christian Maeder
You might use the Prelude function until: until :: (a -> Bool) -> (a -> a) -> a -> a until (> 3) (+ 2) 0 = 4 or for your purpose: until (\ a -> not (goOn(a, f(a))) f ainit http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v%3Auntil http://www.haskell.org/onlinere