[Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Phlex
Hello all, I'm coming from the OO world, and there's something i don't quite understand in the way haskellers manipulate data (as all functional programmers i guess). Let's say i have a deep nested data structure. Universe containing galaxies, containing solar systems, containing planets,

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Donald Bruce Stewart
Phlex: Hello all, I'm coming from the OO world, and there's something i don't quite understand in the way haskellers manipulate data (as all functional programmers i guess). Let's say i have a deep nested data structure. Universe containing galaxies, containing solar systems,

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Phlex
Donald Bruce Stewart wrote: Phlex: On the other side, using the functional paradigm, it seems to me that the function i use in order to create a _new_ inhabitant with a different age will need to have knowledge of the country over it, the planet ..and so on up to the universe...as i need

Re[2]: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Bulat Ziganshin
Hello Phlex, Sunday, June 3, 2007, 11:41:29 AM, you wrote: That's precisely the thing i don't understand. In order to update node 3 with a new pointer, i need to mutate it, so i need to recreate it, and so on up to node 1. yes, that's true Now in this exemple, it's ok since that's a regular

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Phlex
Bulat Ziganshin wrote: Hello Phlex, Sunday, June 3, 2007, 11:41:29 AM, you wrote: That's precisely the thing i don't understand. In order to update node 3 with a new pointer, i need to mutate it, so i need to recreate it, and so on up to node 1. yes, that's true Now in this

[Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread apfelmus
Phlex wrote: Donald Bruce Stewart wrote: Imagine updating a node in a tree by just detaching and reattaching a pointer. [1] [1] / \ / \ [2] [3] update node 5 [2] [3] / \ with value 7 / \ [4] [5]

Re: [Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread Donald Bruce Stewart
apfelmus: Phlex wrote: Donald Bruce Stewart wrote: Imagine updating a node in a tree by just detaching and reattaching a pointer. [1] [1] / \ / \ [2] [3] update node 5 [2] [3] / \ with value 7 / \

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Malcolm Wallace
Phlex [EMAIL PROTECTED] writes: The thing is, now that i have my planet p... i want to change it's age ... and get back the new state of the universe... It is true, there is often a significant amount of boilerplate code needed to wrap a simple planet-change nested deep within a universe

Re[2]: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Bulat Ziganshin
Hello Phlex, Sunday, June 3, 2007, 12:34:26 PM, you wrote: So i need to do something like this : changePlanetAge universe galaxy planet age = ...lots of code, returning a new universe And the same code for all functions updating any of the properties of my planet ... And the same code for

Re: [Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread Phlex
apfelmus wrote: Phlex wrote: Donald Bruce Stewart wrote: Yes and no. The point is that if you can't automate it, you have to code it by hand anyway which constitutes most of the hairiness. But I know what you mean and there's a nice way to do that with multi-parameter type classes.

Re[2]: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Bulat Ziganshin
Hello Malcolm, Sunday, June 3, 2007, 1:13:06 PM, you wrote: The thing is, now that i have my planet p... i want to change it's age ... and get back the new state of the universe... There has been lots of research into easing the pain of creating this outer traversal code - search for Scrap

[Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread apfelmus
apfelmus wrote: {-# OPTIONS_GHC -fglasgow-exts -#} import Prelude hiding (lookup) class Map map key a | map key - a where lookup :: key - map - Maybe a adjust :: (a - a) - key - map - map instance (Map m k m', Map m' k' a) = Map m (k,k') a where

Re: [Haskell-cafe] Haskell on a PDA (was Implementing Mathematica)

2007-06-03 Thread Philippa Cowderoy
On Sat, 2 Jun 2007, Fritz Ruehr wrote: I seem to recall that Aarne Ranta ran Hugs on a (Sharp) Zaurus PDA at one of the ICFPs a few years back. Aha, here in fact is a picture of his GF (Grammatical Framework), written in Haskell, running on a Zaurus: I've got Hugs and GHC both running under

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Tillmann Rendel
Hello, Phlex wrote: changePlanetAge universe galaxy planet age = ...lots of code, returning a new universe And the same code for all functions updating any of the properties of my planet ... And the same code for all functions updating properties of a country on this planet... In functional

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Phlex
Tillmann Rendel wrote: Hello, Phlex wrote: changePlanetAge universe galaxy planet age = ...lots of code, returning a new universe And the same code for all functions updating any of the properties of my planet ... And the same code for all functions updating properties of a country on this

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Claus Reinke
hi there, Let's say i have a deep nested data structure. Universe containing galaxies, containing solar systems, containing planets, containing countries, containing inhabitants, containing ...whatever. Using the OO paradigm, once i get a reference to an inhabitant, i can update it quite

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Felipe Almeida Lessa
On 6/3/07, Tillmann Rendel [EMAIL PROTECTED] wrote: In functional programming, problems of the kind and the same code for all functions doing something related are most often solved by introducing higher order functions. Let's try to decompose the problem as follows: [snip] Now I've got one

[Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread Christopher Lane Hinson
Let's say i have a deep nested data structure. Universe containing galaxies, containing solar systems, containing planets, containing countries, containing inhabitants, containing ...whatever. Oh. I had /exactly/ this problem. If you use separate types (i.e. a newtyped integer, acting

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Vincent Kraeutler
Phlex wrote: This is very informative, and easier to grasp for such a newbie as me. So the idea is to take the changing function down the chain, i knew this couldn't be that hard ! Still this requires indeed to think different, I guess i'm up for quite a few exercises in order to wrap my mind

[Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread Arie Peterson
You could also use 'compositional functional references'. These are introduced in the paper A Functional Programming Technique for Forms in Graphical User Interfaces by Sander Evers, Peter Achten and Jan Kuper. === Introduction === There are two things one typically wants to do when working with

[Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread Stefan O'Rear
(Sorry to break the thread, but mutt somehow managed to eat the message I'm replying to...) Arie Peterson: You could also use 'compositional functional references'. These are introduced in the paper A Functional Programming Technique for Forms in Graphical User Interfaces by Sander Evers,

Re: [Haskell-cafe] Re: I just don't get it (data structures and OO)

2007-06-03 Thread Neil Mitchell
Hi You could also use 'compositional functional references'. These are introduced in the paper A Functional Programming Technique for Forms in Graphical User Interfaces by Sander Evers, Peter Achten and Jan Kuper. I've written a template haskell function to derive Refs from a data

[Haskell-cafe] Ref and Derive

2007-06-03 Thread Arie Peterson
Hello, Stefan O'Rear wrote: I've implemented this in Derive[1] in 12 minutes, counting the time required to re-familiarize with the code. The patch is at [2] and has also been darcs sent. Neil Mitchell wrote: It's been applied, and is now in the main repo. Wow, that was fast. I didn't

Re: [Haskell-cafe] I just don't get it (data structures and OO)

2007-06-03 Thread Ketil Malde
On Sun, 2007-06-03 at 09:02 -0300, Felipe Almeida Lessa wrote: On 6/3/07, Tillmann Rendel [EMAIL PROTECTED] wrote: In functional programming, problems of the kind and the same code for all functions doing something related are most often solved by introducing higher order functions. Let's

Re: [Haskell-cafe] Ref and Derive

2007-06-03 Thread Neil Mitchell
Hi Speaking of Derive: I tried to install it just a few days ago, and failed. 'Derive' needed 'filepath-any', which needed 'directory-any', which I couldn't find (in Hackage or on Neil's website). Either: 1) Use GHC 6.6.1, which comes with filepath 2) Use the hackage version:

[Haskell-cafe] Template Haskell, information about data constructor types

2007-06-03 Thread Neil Mitchell
Hi I'm trying to write a function: reaches :: Type - Q [Type] The intention is that reaches (Either Bool [Int]) would return [Either Bool [Int], Bool, [Int], Int] - i.e. all types which are contained by the initial type at any level. I took a shot at this: getTypes :: Type - Q [Type]

Re: [Haskell-cafe] Re: Just for a laugh...

2007-06-03 Thread Rafael Almeida
The site seems to be asking for the internal floating point representation. So it doesn't matter if it's IEEE 754, if the ints are 2-complements, or whatever. I used this code as a quick hack for one of my programs, but I think it would work in this case. It should work for any Storable type.

Re: [Haskell-cafe] Re: Just for a laugh...

2007-06-03 Thread Rafael Almeida
On 6/3/07, Rafael Almeida [EMAIL PROTECTED] wrote: The site seems to be asking for the internal floating point representation. So it doesn't matter if it's IEEE 754, if the ints are 2-complements, or whatever. I used this code as a quick hack for one of my programs, but I think it would work in

Re: [Haskell-cafe] Re: Just for a laugh...

2007-06-03 Thread Donald Bruce Stewart
almeidaraf: On 6/3/07, Rafael Almeida [EMAIL PROTECTED] wrote: The site seems to be asking for the internal floating point representation. So it doesn't matter if it's IEEE 754, if the ints are 2-complements, or whatever. I used this code as a quick hack for one of my programs, but I think

[Haskell-cafe] Why does the class called Real support only rationals, and not all reals?

2007-06-03 Thread bretm
I just got started learning Haskell a few days ago. I've implemented a numeric data type that can represent some irrational numbers exactly, and I'd like to instantiate the RealFrac class so I can do truncate, round, etc., in the most natural way in the language. Implementing properFraction