[Haskell-cafe] matching constructors
Vadim Zaliva
lord at crocodile.org
Fri Mar 5 15:48:25 EST 2004
On Mar 5, 2004, at 12:41, Brandon Michael Moore wrote:
> At the lower level of remimplementing your functions I can suggest a
> few
> things.
Brandon,
Thanks for great suggestions! Following them, here is how I redone the
code:
...
import Data.Maybe
import Data.Either
import Data.Typeable
...
data Flag = Verbose |
Input String |
Output String |
Filter String
deriving Show Data
instance Eq Flag where
x == y = toConstr x == toConstr y
findFlag :: Flag -> [Flag] -> Flag
findFlag f fs = fromMaybe f (find (==f) fs)
The only problem is my GHC does not seems to find 'Data' class and I am
getting following errors:
Type constructor or class not in scope: `Data'
Variable not in scope: `toConstr'
Variable not in scope: `toConstr'
Also I have style question: What is the best way to define equality
test in this example:
1. Via instantiating EQ class
2. via standalone function (I can define sameConstr Flag -> Flag ->
Bool)
3. inline lambda expression passed to find
I am leaning towards #2 or #3.
Vadim
--
"La perfection est atteinte non quand il ne reste rien a ajouter, mais
quand il ne reste rien a enlever." (Antoine de Saint-Exupery)
More information about the Haskell-Cafe
mailing list