Java - Haskell adjustment

Hi, its Ryan here... I've just come from an intensive course in java and have been thrown into the imperative world of haskell. The problem that I have is extremely simple in java but I am having trouble adjusting my old mindset. A multiset is a collection of items. Each item may occur one or more times in the multiset. All items are of the same type. The scenario we could use is a students' grades for their A levels: 3A, 4B and 2C grades for our pupil 'x'. A multiset may be implemented by a list... so ['A', 'A', 'A', 'B', 'B', 'B', 'B, 'C', 'C'] but this very ineffiecient and tedious. How might one set out into putting this into action.... thanks... Any help that complements my ideas is welcome _________________________________________________________________ Feel like a local wherever you go. http://www.backofmyhand.com

Ryan Bloor wrote:
Hi, its Ryan here...
I've just come from an intensive course in java and have been thrown into the imperative world of haskell.
The problem that I have is extremely simple in java but I am having trouble adjusting my old mindset.
A multiset is a collection of items. Each item may occur one or more times in the multiset. All items are of the same type.
The scenario we could use is a students' grades for their A levels: 3A, 4B and 2C grades for our pupil 'x'. A multiset may be implemented by a list... so ['A', 'A', 'A', 'B', 'B', 'B', 'B, 'C', 'C'] but this very ineffiecient and tedious.
How might one set out into putting this into action.... thanks...
Why do you think a list is inefficient and tedious? It sounds fine for this simple application. If you have complexity constraints which rule a list out, then consider Data.Sequence. Actually Data.Sequence has a very similar API to the programmer; you will feel much like you're using List, but it is faster for certain things. (most things, in fact). Jules

On Mon, Oct 15, 2007 at 03:49:44PM +0100, Ryan Bloor wrote:
Hi, its Ryan here...
I've just come from an intensive course in java and have been thrown into the imperative world of haskell.
The problem that I have is extremely simple in java but I am having trouble adjusting my old mindset.
A multiset is a collection of items. Each item may occur one or more times in the multiset. All items are of the same type.
The scenario we could use is a students' grades for their A levels: 3A, 4B and 2C grades for our pupil 'x'. A multiset may be implemented by a list... so ['A', 'A', 'A', 'B', 'B', 'B', 'B, 'C', 'C'] but this very ineffiecient and tedious.
You might try, for example, rle encoding : [(3, 'A'), (4, 'B'), (2, 'C')]. Don't know if this would be more efficient for your task, but if you wish to 'just optimize something' you can give that a try.
How might one set out into putting this into action.... thanks...
Any help that complements my ideas is welcome
_________________________________________________________________ Feel like a local wherever you go. http://www.backofmyhand.com _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- pierre

On Mon, 15 Oct 2007, Ryan Bloor wrote:
Hi, its Ryan here...
I've just come from an intensive course in java and have been thrown into the imperative world of haskell.
The problem that I have is extremely simple in java but I am having trouble adjusting my old mindset.
A multiset is a collection of items. Each item may occur one or more times in the multiset. All items are of the same type.
The scenario we could use is a students' grades for their A levels: 3A, 4B and 2C grades for our pupil 'x'.
A multiset may be implemented by a list... so ['A', 'A', 'A', 'B', 'B', 'B', 'B, 'C', 'C'] but this very ineffiecient and tedious.
You might model it using Map Char Int which maps each multiset element to its multiplicity. Maybe 'Char' is not the appropriate type, but an enumeration? data Grade = A | B | C | D | E deriving (Show, Eq, Ord) then use 'Map Grade Int'
participants (4)
-
Henning Thielemann
-
Jules Bean
-
pierre
-
Ryan Bloor