[Haskell-cafe] Trying to implement this code

Dmitry Vyal akamaus at gmail.com
Tue Apr 19 02:26:11 EDT 2005

Scott Turner wrote:

> It's a valid approach.  Rather than declare an Updateable class, I'd just have 
> the update function be a parameter of ins_in_tree.  Also, the key and value 
> types can be independent parameters of BinTree.

I started to refactor my code as you suggested. I inserted update
function in the middle of parameter list of ins_in_tree function. Just
because this order seemed to be logical to me.
ins_in_tree :: (Ord a) =>  BinTree a -> (a->a) -> a -> BinTree a

But soon I found that i need partial parametrization in order to rewrite
old ins_list:
ins_list lst = foldl ins_in_tree  Leaf (map wrap lst)

So i had to change parameter order in ins_in_tree:
ins_in_tree :: (Ord a) => (a->a) -> BinTree a -> a -> BinTree a

and then wrote:
ins_list lst = foldl (ins_in_tree update_stat) Leaf  (map wrap lst)
update_stat (Word_stat s i) = Word_stat s (i+1)

That worked, but what if i would need another order somethere further?
Will I have to write some kind of wrapper like
ins_in_tree' a b c = ins_in_tree b a c

Does better solution exist?

More information about the Haskell-Cafe mailing list