Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg
On 28 Mar 2008, at 03:03, Ryan Ingram wrote: Another way to defer the evaluation of the second argument of (-+) is like this: (-+) :: a - List a - List a x -+ y = List(f) where f 0 = x f k = case y of List g - g (k-1) This is exactly what the lazy pattern will do at compile-time.

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg
On 28 Mar 2008, at 03:03, Ryan Ingram wrote: Another way to defer the evaluation of the second argument of (-+) is like this: (-+) :: a - List a - List a x -+ y = List(f) where f 0 = x f k = case y of List g - g (k-1) This is exactly what the lazy pattern will do at compile-time. Does

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg
On 28 Mar 2008, at 03:03, Ryan Ingram wrote: Another way to defer the evaluation of the second argument of (-+) is like this: (-+) :: a - List a - List a x -+ y = List(f) where f 0 = x f k = case y of List g - g (k-1) This is exactly what the lazy pattern will do at compile-time. Does

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-28 Thread Hans Aberg
I have fixed the problem now. In the last letter, with the Natural class, I had not added instance Num Natural where (N x) - (N y) = N(x - y) which the Ordinal class then in fact has one. Then it turns out that it is merely the fact that show had some cases looking at the list length

[Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Hans Aberg
When experimenting with list index sets (i.e. lists more general than provided by Haskell), I arrived at the problem that in the example code below for example h(list 6) does not (in Hugs) write out the beginning of the list lazily. It does work for list 6 first (list 6) rest (list

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Claude Heiland-Allen
Hans Aberg wrote: When experimenting with list index sets (i.e. lists more general than provided by Haskell), I arrived at the problem that in the example code below for example h(list 6) does not (in Hugs) write out the beginning of the list lazily. It does work for list 6 first (list

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Luke Palmer
On Thu, Mar 27, 2008 at 2:18 PM, Claude Heiland-Allen The combination of (-+) and h is too strict, this modification works: (-+) :: a - List a - List a x -+ ~(List y) = List(f) where -- lazy pattern match f 0 = x f k = y(k-1) More to the point, if List is declared as:

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Hans Aberg
On 27 Mar 2008, at 15:18, Claude Heiland-Allen wrote: The combination of (-+) and h is too strict, this modification works: (-+) :: a - List a - List a x -+ ~(List y) = List(f) where -- lazy pattern match f 0 = x f k = y(k-1) Thank you for the fast response. Yes, that might be what I

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Hans Aberg
On 27 Mar 2008, at 15:32, Luke Palmer wrote: More to the point, if List is declared as: newtype List a = List (Integer - a) Instead of with data, it also works. The problem, as was stated, was that -+ is too strict. That is, without the ~ there, -+ evaluates its right argument to make

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Miguel Mitrofanov
Hmmm, seems like your (-+) is not lazy enough. Since pattern matching is strict by default, you have anything -+ (_|_) = (_|_) Therefore, the function, which is constantly (_|_), is a fixed point for the equation defining h. In other words, if you define h' x = undefined then you have h'

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Hans Aberg
On 27 Mar 2008, at 15:58, Miguel Mitrofanov wrote: Hmmm, seems like your (-+) is not lazy enough. ... You can fix it by defining (-+) as x -+ ~(List y) = ... Yes, this has been pointed out... Since pattern matching is strict by default, you have anything -+ (_|_) = (_|_) Therefore,

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Hans Aberg
On 27 Mar 2008, at 17:51, Luke Palmer wrote: By your naming, am I correct in assuming that you're implementing transfinite lists? If so, cool! Yes, it is an old idea I brought up now. If list length is written also for infinite lists, then concatenated lists get indexed by the sum of

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Hans Aberg
On 27 Mar 2008, at 17:51, Luke Palmer wrote: A more standard way to do this would be: data List a = List (Ordinal - a) Ordinal I used data List a = Empty | (Ordinal-a) :+ Ordinal which might then be simplified by dropping Empty. Hans Aberg

Re: [Haskell-cafe] Recursion problem in infinite list model

2008-03-27 Thread Ryan Ingram
Another way to defer the evaluation of the second argument of (-+) is like this: (-+) :: a - List a - List a x -+ y = List(f) where f 0 = x f k = case y of List g - g (k-1) This is exactly what the lazy pattern will do at compile-time. Does this give you a better understanding of how lazy

[Haskell-cafe] recursion issues...

2007-11-10 Thread Ryan Bloor
hiya I was wondering how I would get the second function do recursively do the function for poolNews xs tried that and it fails. Ryan --Give wins, draws a rating. poolNews :: Result - PoolNews - PoolNews poolNews (a,b,c,d,e) (home,away,goaless,scoredraw) | c d =

Re: [Haskell-cafe] recursion issues...

2007-11-10 Thread Andrew Wagner
Looks to me like you want: poolNewsB = foldr poolNews (0,0,0,0) On Nov 10, 2007 11:54 AM, Ryan Bloor [EMAIL PROTECTED] wrote: hiya I was wondering how I would get the second function do recursively do the function for poolNews xs tried that and it fails. Ryan --Give wins, draws

Re: [Haskell-cafe] recursion issues...

2007-11-10 Thread Brent Yorgey
On Nov 10, 2007 11:54 AM, Ryan Bloor [EMAIL PROTECTED] wrote: hiya I was wondering how I would get the second function do recursively do the function for poolNews xs tried that and it fails. Ryan --Give wins, draws a rating. poolNews :: Result *-* PoolNews *-* PoolNews

[Haskell-cafe] Recursion

2007-03-06 Thread Dave
Does the following code increase the level of recursion once for each input line or is the recursive construct converted to an iteration? Thanks, Dave Feustel main :: IO () main = do line - getLine processIt line main processIt :: String - IO () processIt s = do print (length s)

Re: [Haskell-cafe] Recursion

2007-03-06 Thread Bryan Burgers
On 3/6/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Does the following code increase the level of recursion once for each input line or is the recursive construct converted to an iteration? Thanks, Dave Feustel main :: IO () main = do line - getLine processIt line main processIt ::

Re: [Haskell-cafe] Recursion

2007-03-06 Thread Jefferson Heard
Bryan, The code here does not take advantage of laziness, which is probably what you want to do, as it is much cleaner to look at and more Haskell like. In answer to your question it is tail recursive, and strict, which means that in some compilers, with some optimization flags (i.e. GHC)

Re: [Haskell-cafe] Recursion

2007-03-06 Thread Kirsten Chevalier
On 3/6/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Does the following code increase the level of recursion once for each input line or is the recursive construct converted to an iteration? As was pointed out, tail recursion in Haskell isn't straightforward. The answer may also depend on

Re: [Haskell-cafe] Recursion in Haskell

2007-02-19 Thread kahl
For absorbing the functional style of programming (which is what you really should be working on at this point), For functional style and the reasoning attitude associated with lazy functional programming, the following book is a good introduction: @Book{Bird-2000, author = {Richard

Re: [Haskell-cafe] Recursion in Haskell

2007-02-19 Thread Matthew Brecknell
P. R. Stanley: is there another general pattern for mylen, head or tail? mylen [] = 0 mylen (x:xs) = 1 + mylen (xs) head [] = error what head? head (x:xs) = x tail [] = error no tail tail (x:xs)= xs Benjamin Franksen: Another very common 'pattern' is to factor the recursion into a

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread P. R. Stanley
Brandon, Chris, Don, gentlemen, Thank you all for your swift and well-written answers. I should point out that I'm coming to functional programming with a strong background in programming in C and C-type languages. I am also very new to the whole philosophy of functional programming. Hence my

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread Brandon S. Allbery KF8NH
On Feb 18, 2007, at 21:26 , P. R. Stanley wrote: mylen (x:y) = 1 + mylen y The base case, if that is the right terminology, stipulates that the recursion ends with an empty list and returns 0. Simple though one question - why does mylen require the parentheses even when it is evaluating

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread Michael Vanier
P. R. Stanley wrote: Brandon, Chris, Don, gentlemen, Thank you all for your swift and well-written answers. I should point out that I'm coming to functional programming with a strong background in programming in C and C-type languages. I am also very new to the whole philosophy of functional

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread Brandon S. Allbery KF8NH
On Feb 18, 2007, at 21:44 , Michael Vanier wrote: I think what you're asking here is why you need the parens around (x:y) in the second case. Function application doesn't use parentheses Function application never applies to pattern matching. The usual answer to this is category theory

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread Michael Vanier
Brandon S. Allbery KF8NH wrote: On Feb 18, 2007, at 21:44 , Michael Vanier wrote: I think what you're asking here is why you need the parens around (x:y) in the second case. Function application doesn't use parentheses Function application never applies to pattern matching. You're

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread P. R. Stanley
Chaps, is there another general pattern for mylen, head or tail? mylen [] = 0 mylen (x:xs) = 1 + mylen (xs) head [] = error what head? head (x:xs) = x tail [] = error no tail tail (x:xs)= xs This pattern matching reminds me of a module on formal spec I studied at college. What are the

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread Michael Vanier
P. R. Stanley wrote: What are the pre-requisites for Lambda calculus? Thanks Paul Learning lambda calculus requires no prerequisites other than the ability to think clearly. However, don't think that you need to understand all about lambda calculus in order to learn Haskell. It's more

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread Brandon S. Allbery KF8NH
On Feb 18, 2007, at 22:22 , P. R. Stanley wrote: is there another general pattern for mylen, head or tail? Those are basically it, aside from optionally replacing the unused variables with _. What are the pre-requisites for Lambda calculus? Lambda calculus isn't related to what's

Re: [Haskell-cafe] Recursion in Haskell

2007-02-18 Thread Derek Elkins
Michael Vanier wrote: P. R. Stanley wrote: What are the pre-requisites for Lambda calculus? Thanks Paul Learning lambda calculus requires no prerequisites other than the ability to think clearly. However, don't think that you need to understand all about lambda calculus in order to learn

[Haskell-cafe] Recursion in Haskell

2007-02-17 Thread P. R. Stanley
Hi I understand the basic principle of recursion but have difficulty with the following: -- a recursive function -- for calculating the length of lists myLen [] = 0 myLen (x:xs) = 1 + myLen xs What's happening here? Top marks for a comprehensive jargon-free explanation. Thanks in advance Paul

Re: [Haskell-cafe] Recursion in Haskell

2007-02-17 Thread Brandon S. Allbery KF8NH
On Feb 17, 2007, at 21:32 , P. R. Stanley wrote: Hi I understand the basic principle of recursion but have difficulty with the following: -- a recursive function -- for calculating the length of lists myLen [] = 0 myLen (x:xs) = 1 + myLen xs What's happening here? This definition uses

Re: [Haskell-cafe] Recursion in Haskell

2007-02-17 Thread Donald Bruce Stewart
prstanley: Hi I understand the basic principle of recursion but have difficulty with the following: -- a recursive function -- for calculating the length of lists myLen [] = 0 myLen (x:xs) = 1 + myLen xs So this is a definition for the 'length' function on lists. The list data structure

Re: [Haskell-cafe] Recursion in Haskell

2007-02-17 Thread Chris Eidhof
The definition of myLen says: myLen [] = 0 The length for an empty list is zero myLen (x:xs) = 1 + myLen xs The length of a list containing x and some other stuff (xs) is 1 + (the length of the other stuff). So basically, if you've got a list [1,2,3], it will try to do this: myLen