Re: [Haskell-cafe] beginner's problem about lists

2006-10-19 Thread Eugene Crosser
On Tue, 10 Oct 2006 [EMAIL PROTECTED] wrote: Hi all, I'm trying to implement a function that returns the shorter one of two given lists, something like shorter :: [a] - [a] - [a] such that shorter [1..10] [1..5] returns [1..5], and it's okay for shorter [1..5] [2..6] to return either.

Re: [Haskell-cafe] beginner's problem about lists

2006-10-19 Thread Eugene Crosser
Sorry, I realized that it does not cover the shorter [1..5] (shorter [2..] [3..]) case... Eugene Crosser wrote: On Tue, 10 Oct 2006 [EMAIL PROTECTED] wrote: Hi all, I'm trying to implement a function that returns the shorter one of two given lists, something like shorter :: [a] - [a] -

Re: [Haskell-cafe] beginner's problem about lists

2006-10-12 Thread Stefan Holdermans
Nicolas, I think you gave a fine explanation. Just a few minor remarks... l1 = Cons 3 Nil l2 = Cons 3 _|_ l2 l1 because l1 is more defined. Surely you mean l2 l1, then. Moreover, are you sure you need to define your order in such a way that l2 l1. I'd say, for these purposes, it's

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Malcolm Wallace
ihope [EMAIL PROTECTED] wrote: It's possible to make both infinite list and finite list datatypes: data Inf a = InfCons a (Inf a) data Fin a = FinCons a !(Fin a) | FinNil At least, I think the Fin type there has to be finite... No, your Fin type can also hold infinite values. The

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Duncan Coutts
On Wed, 2006-10-11 at 11:40 +0100, Malcolm Wallace wrote: ihope [EMAIL PROTECTED] wrote: It's possible to make both infinite list and finite list datatypes: data Inf a = InfCons a (Inf a) data Fin a = FinCons a !(Fin a) | FinNil At least, I think the Fin type there has to be

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Matthias Fischmann
On Wed, Oct 11, 2006 at 11:40:59AM +0100, Malcolm Wallace wrote: To: haskell-cafe@haskell.org From: Malcolm Wallace [EMAIL PROTECTED] Date: Wed, 11 Oct 2006 11:40:59 +0100 Subject: Re: [Haskell-cafe] beginner's problem about lists ihope [EMAIL PROTECTED] wrote: It's possible to make

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Malcolm Wallace
Matthias Fischmann [EMAIL PROTECTED] wrote: No, your Fin type can also hold infinite values. let q = FinCons 3 q in case q of FinCons i _ - i == _|_ does that contradict, or did i just not understand what you are saying? That may be the result in ghc, but nhc98 gives the answer 3. It

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread David Sabel
Malcolm Wallace wrote: Matthias Fischmann [EMAIL PROTECTED] wrote: No, your Fin type can also hold infinite values. let q = FinCons 3 q in case q of FinCons i _ - i == _|_ does that contradict, or did i just not understand what you are saying? That may be the result in

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Robert Dockins
On Oct 11, 2006, at 10:14 AM, Malcolm Wallace wrote: Matthias Fischmann [EMAIL PROTECTED] wrote: No, your Fin type can also hold infinite values. let q = FinCons 3 q in case q of FinCons i _ - i == _|_ does that contradict, or did i just not understand what you are saying? That may be

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Matthias Fischmann
Subject: Re: [Haskell-cafe] beginner's problem about lists Matthias Fischmann [EMAIL PROTECTED] wrote: No, your Fin type can also hold infinite values. let q = FinCons 3 q in case q of FinCons i _ - i == _|_ does that contradict, or did i just not understand what you are saying

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Ross Paterson
On Wed, Oct 11, 2006 at 11:04:49AM -0400, Robert Dockins wrote: let q = seq q (FinCons 3 q) in q(beta) We have (from section 6.2): seq _|_ y = _|_ seq x y = yiff x /= _|_ Now, here we have an interesting dilemma. The meaning of a recursive definition is the

Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Robert Dockins
On Oct 11, 2006, at 11:14 AM, Ross Paterson wrote: On Wed, Oct 11, 2006 at 11:04:49AM -0400, Robert Dockins wrote: let q = seq q (FinCons 3 q) in q(beta) We have (from section 6.2): seq _|_ y = _|_ seq x y = yiff x /= _|_ Now, here we have an interesting

Re: Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Nicolas Frisby
For my own edification (experts: please remark if I stray from any conventional notions--be as picky as possible) and perhaps for anyone who didn't quite grok Ross Paterson's punchline, I'm going to try to answer the question How does seq affect the definedness CPO? At the heart of these two

Re: Re: [Haskell-cafe] beginner's problem about lists

2006-10-11 Thread Cale Gibbard
On 11/10/06, Nicolas Frisby [EMAIL PROTECTED] wrote: Intuitively q = lfp f = f(f(f(f(f(f (f(f(f _|_)))...)(*) r = lfg g = g(g(g(g(g(g (g(g(g _|_)))...) (**) This way of writing it would imply (at least to me) that the number of f's and g's involved is

Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread Neil Mitchell
Hi, The trick is not call length, since length demands the whole of a list, and won't terminate on an infinite list. You will want to recurse down the lists. Is this a homework problem? It's best to declare if it is, and show what you've managed to do so far. Thanks Neil On 10/10/06, [EMAIL

Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread Matthias Fischmann
On Tue, Oct 10, 2006 at 08:10:44PM +0800, [EMAIL PROTECTED] wrote: To: haskell-cafe@haskell.org From: [EMAIL PROTECTED] Date: Tue, 10 Oct 2006 20:10:44 +0800 Subject: [Haskell-cafe] beginner's problem about lists Hi all, I'm trying to implement a function that returns the shorter one of

Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread Lennart Augustsson
On Oct 10, 2006, at 08:49 , Matthias Fischmann wrote: On Tue, Oct 10, 2006 at 08:10:44PM +0800, [EMAIL PROTECTED] wrote: To: haskell-cafe@haskell.org From: [EMAIL PROTECTED] Date: Tue, 10 Oct 2006 20:10:44 +0800 Subject: [Haskell-cafe] beginner's problem about lists Hi all, I'm trying to

Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread Henning Thielemann
On Tue, 10 Oct 2006 [EMAIL PROTECTED] wrote: Hi all, I'm trying to implement a function that returns the shorter one of two given lists, something like shorter :: [a] - [a] - [a] such that shorter [1..10] [1..5] returns [1..5], and it's okay for shorter [1..5] [2..6] to return either.

Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread Colin DeVilbiss
On 10/10/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I'm trying to implement a function that returns the shorter one of two given lists, something like shorter :: [a] - [a] - [a] However, it becomes difficult when dealing with infinite lists, for example, shorter [1..5] (shorter [2..]

Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread falseep
Thanks for your reply. I tried afew ways butnoneworked.One islike: shorter as bs = f id id as bs wheref ca cb [] _ =ca[] f ca cb _ [] = cb []f ca cb (a:as) (b:bs) = f (ca.(a:)) (cb.(b:)) as bs However this will result in a non-terminating loop for shorter [1..]

Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread Neil Mitchell
Hi However this will result in a non-terminating loop for shorter [1..] [2..], since the first two patterns of f shall never match. The specification of your problem makes this a guarantee. How do you know that a list is finite? You find the [] at the end. How do you know a list is infinite?

Re: Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread Nicolas Frisby
I suppose using indicative types (dependent style) is out of the question? I presume i) that would over-simplify the problem and ii) we're tied to the [-] type. It deserves mention no less. data Fin data Inf data List l a = Cons a (List l a) | Nil shorter :: List Inf a - List Inf a -

Re: Re: [Haskell-cafe] beginner's problem about lists

2006-10-10 Thread ihope
On 10/10/06, Nicolas Frisby [EMAIL PROTECTED] wrote: data Fin data Inf data List l a = Cons a (List l a) | Nil It's possible to make both infinite list and finite list datatypes: data Inf a = InfCons a (Inf a) data Fin a = FinCons a !(Fin a) | FinNil At least, I think the Fin type there