divarvel / Arithmetic-Trees

A simple datastructure used to describe arithmetic expressions.
4 stars 2 forks source link

Make more use of haskell typeclasses #2

Open jtanguy opened 12 years ago

jtanguy commented 12 years ago

Instead of defining a Tree as a data, we could define it as a typeclass:

class Tree a where
    eval :: Tree -> a
    derive :: Tree -> Tree
    replace :: Tree -> a -> Tree
    clean :: Tree -> Tree

And then define leaves, unary and binary operators as instances of Tree Float

divarvel commented 12 years ago

Good idea. I'll do that this evening. I'll try to make tree an instance of Foldable as well.