Welcome to Haskell! =) > But now I don't know how to dynamically add new spells (new spells can be > created in my gameplay). Since I can't assign a new value to the `spells' > variable (Data.Map.insert returns a new map), I just don't know where to > go.
Do distinguish *pure function* concept and *action with side effects* concept. The default in FP (Funct. Progr.) paradigm usualy is *pure function*, if *action with side effects* is avoidable. Pure functions deal with immutable memory "objects". So in your case, whenever you add a new spell, you get a new character (since your chacter's "essence" is a spell list). That way after calculating *addNewSpell* you will have 2 versions of character: a new one (with spells list bigger), an the original one. Since old one usualy drop out of the scope (while program evaluation progresses) it gets *garbage collected* (note: garbage collection showed up in FP already in 1960s). addNewSpell :: Character -> Spell -> Character addNewSpell char_old_version spell_to_add = ... main = let char_new_version = addNewSpell char_old_version new_spell in putStrLn $ show char_new_version where char_old_version = Charcter {...} new_spell = Spell { .... } Have luck, with the brain rewriting! =) Belka -- View this message in context: http://www.nabble.com/using-haskell-for-a-project-tp23348425p23352598.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe