Re: [Haskell-cafe] Re: Non Empty List?

2009-06-05 Thread Ketil Malde
GüŸnther Schmidt gue.schm...@web.de writes: I need a data structure as in my example without the [] being possible to be empty. Well, a list can by definition be empty, so this is clearly impossible. The best you can do is to hide the constructors and have smart constructor functions that

[Haskell-cafe] Re: Non Empty List?

2009-06-05 Thread Tillmann Rendel
Hi, please write to the whole list, not just me. There are a lot of people around who can help you. MH wrote: Rendel do you mind to explain to me how Container a = Many a (Container [a]) prevents user from creating an empty list? I did try the following: let a = Many string a :: Container

[Haskell-cafe] Re: Non Empty List?

2009-06-05 Thread MH
I actually meant data Container a = Many a(Container a) but here is what I don't understand (fyi, I am a beginner) how can you construct this container? I can do let a = Many somestring - and I will get back a function but I can not do let a = Many 'a' somestring - because the second param is

Re: [Haskell-cafe] Re: Non Empty List?

2009-06-05 Thread Ketil Malde
MH mha...@gmail.com writes: data Container a = Many a(Container a) but here is what I don't understand (fyi, I am a beginner) how can you construct this container? I can do let a = Many somestring - and I will get back a function but I can not do let a = Many 'a' somestring - because the

Re: [Haskell-cafe] Re: Non Empty List?

2009-06-05 Thread Jason Dagit
On Fri, Jun 5, 2009 at 2:58 PM, MH mha...@gmail.com wrote: I actually meant data Container a = Many a(Container a) but here is what I don't understand (fyi, I am a beginner) how can you construct this container? I can do I think I saw the above definition described as a coalgebra or

Re: [Haskell-cafe] Re: Non Empty List?

2009-06-05 Thread Luke Palmer
On Fri, Jun 5, 2009 at 4:13 PM, Jason Dagit da...@codersbase.com wrote: On Fri, Jun 5, 2009 at 2:58 PM, MH mha...@gmail.com wrote: I actually meant data Container a = Many a(Container a) but here is what I don't understand (fyi, I am a beginner) how can you construct this container? I

[Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread GüŸnther Schmidt
Hi Jake, Jake McArthur schrieb: GüŸnther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I think you meant to do either data Container a = Single a | Many a (Container

[Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread GüŸnther Schmidt
Hi Tom, thanks for replying, no, I'm not looking for streams. I hope I made myself a bit more clear in my response to Jake. Günther Tom Lokhorst schrieb: Are you looking for something like Streams [1]? They're infinite sequences, defined like this: data Stream a = Cons a (Stream a) They

Re: [Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread Dan Weston
Unless I'm missing something in your description, why not data Container a = Single a | Many a a [a] Dan GüŸnther Schmidt wrote: Hi Jake, Jake McArthur schrieb: GüŸnther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would

[Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread GüŸnther Schmidt
Dan Weston schrieb: Unless I'm missing something in your description, why not data Container a = Single a | Many a a [a] Hi Dan, the above solution would still allow to construct, for instance, Many 5 42 [] :: Container Int The reason why I'm trying to find the design for a data

Re: [Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread Tillmann Rendel
Hi Günther, GüŸnther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above I need a data structure as in my example without the [] being possible to be empty. So lets write a variant of list which cannot be empty. A usual list is empty, or a head and a tail:

Re: [Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread Tony Morris
I note that you didn't address the suggestion of a zipper. GüŸnther Schmidt wrote: Dan Weston schrieb: Unless I'm missing something in your description, why not data Container a = Single a | Many a a [a] Hi Dan, the above solution would still allow to construct, for instance, Many 5

[Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread GüŸnther Schmidt
Hi Tony, that's because I wasn't sure whether or not it would be applicable here. As with monads, continuations, delimited continuations and quite a number of other high level concepts I only understand them in part even though I realize at the same time that understanding them fully would

[Haskell-cafe] Re: Non Empty List? - Apologies

2009-06-04 Thread GüŸnther Schmidt
Hi Jake, apologies, Jake McArthur schrieb: GüŸnther Schmidt wrote: data Container a = Single a | Many a [a] but the problem above is that the data structure would allow to construct a Many 5 [] :: Container Int. I think you meant to do either data Container a = Single a | Many a

Re: [Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread Jeff Wheeler
On Fri, 2009-06-05 at 02:08 +0200, GüŸnther Schmidt wrote: As for the zipper: In some of the examples I've seen, the zipper is implemented on top of an underlying data structure, but not the data structure itself. In my app I was actually going to pull a zipper over it, once I had the

[Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread GüŸnther Schmidt
Hi Tillmann, thank you for the elaborate example. This is exactly what it took for me to realize that you and Jake have indeed given me the solution that I need. I had a very hard time getting my head around it, but to my defense I'm usually working on this stuff in the wee hours. :)

[Haskell-cafe] Re: Non Empty List?

2009-06-04 Thread GüŸnther Schmidt
Hi Jeff, it might actually be, I'll check it out after a good nights sleep. Apparently working on this in the wee hours only leads to self embarrassing requests for help. Actually when it comes to the underlying data structure, Jake and Tillmann have already found it for me, even though I