[Haskell-cafe] How can i safely change the value of specified key ?

Kyle Murphy orclev at gmail.com
Thu Oct 22 10:48:52 EDT 2009

- Sorry for the late reply on this, I actually sent it last night before I
went to bed but accidentally sent it only to Bulat, re-sending it now for
the entire list -

As Bulat said, it sounds like you're not fully understanding functional
programming. You really should read one of the better tutorials or books on
Haskell like Real World Haskell (you can read it for free online, just
google for it), as it seems like you're trying to use a advanced feature of
the language (IORefs) that's designed to help solve some particularly
difficult problems in order to treat the language more like a procedural
language (which is a really bad way to approach it). This would be something
like if you decided to learn Java by only ever have one class that consisted
of nothing but a whole bunch of public static methods, it pretty much misses
the point of the language.

Try not to think of variables as places to store values, instead think of
them as functions that take zero or more arguments.

when you do something like
> let foo = [1,2,3]
don't think of foo as a variable that contains a list of numbers, instead
think of foo as a function that doesn't take any arguments and returns a
list of numbers (in this case a constant list). You should also concentrate
on ways data can be transformed particularly using higher order functions
like map and foldr.

For instance, if you want to convert a list like [1,2,3] into one like
[(1,1),(2,2),(3,3)] (that is, convert [Int] to [(Int, Int)]) you can use map
or zip like so:
> map (\x -> (x,x)) [1,2,3] -- applies a function to each member, in this
case the lambda \x -> (x,x) which just makes a tuple
> zip [1,2,3] [1,2,3] -- combines two lists into one by making each element
of the joined list a tuple of one element from each list

-R. Kyle Murphy
Curiosity was framed, Ignorance killed the cat.

On Thu, Oct 22, 2009 at 03:41, Bulat Ziganshin <bulat.ziganshin at gmail.com>wrote:

> Hello zaxis,
> Thursday, October 22, 2009, 11:28:14 AM, you wrote:
> > then if i want to change aaa to [(1,1),(2,222),(3,3)] , what's the best
> way
> ... well, anyway what you are doing isn't very haskellish. it may be
> considered as advanced topic but basically, best way to compute
> something in Haskell is to construct pure function
> --
> Best regards,
>  Bulat                            mailto:Bulat.Ziganshin at gmail.com
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091022/43ba5884/attachment.html

More information about the Haskell-Cafe mailing list