[Haskell-cafe] matching constructors
Vadim Zaliva
lord at crocodile.org
Mon Mar 8 10:59:14 EST 2004
On Mar 5, 2004, at 15:48, Vadim Zaliva wrote:
OK, I figured it out. For sake of other novices like me here is what
you need
to do to make it work.
0. Need to import Data.Generics
1. Compile with '-fglasgow-exts' flag
2. When deriving from Data you also need to derive from Typeable.
It slightly bothers me that this solution seems to be using
non-standard GHC extensions.
Vadim
>
> 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)
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
--
"La perfection est atteinte non quand il ne reste rien a ajouter, mais
quand il ne reste rien a enlever." (Antoine de Saint-Exupery)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2388 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/haskell-cafe/attachments/20040308/c780c9e2/smime.bin
More information about the Haskell-Cafe
mailing list