[Haskell-cafe] newbie: maintaining relationships

geoffrey lordgeoffrey at optushome.com.au
Fri May 23 14:07:03 EDT 2008


I am learning haskell and i need some advice about writing
functional-style code.

Give the following code below, my question is - how do i setup a
dependency of User on Common?

Obviously what i have there is wrong, because a change in common (i know
it's actually immutable) is not reflected in the version captured by
User. I understand why my current approach has not a chance a of
working, I am using it to, hopefully, illustrate my goal.

Thanks for any suggestions

> data Common = Common {
> 				cName :: String,
> 				cValue :: Int
> 				} deriving (Show)
> data User = User {
> 				uCommon	:: Common
> 				} deriving (Show)
> makeWorld = (commons, users)
> 	where
> 	commons = [Common "A" 1, Common "B" 2]
> 	users	= [User (head commons)]
> 	
> main = do
> 	let world = makeWorld
> 	putStrLn (show world)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080524/c04f7d8e/attachment.htm


More information about the Haskell-Cafe mailing list