[Haskell] How to define gunfold on List?
José Pedro Magalhães
jpm at cs.uu.nl
Sun Jan 18 04:56:53 EST 2009
There's no difference. See
You can also see many other instances there.
On Sun, Jan 18, 2009 at 10:50, haihualin <haihualin at 163.com> wrote:
> Does some one know how to define gunfold on recursive data struction like
> The ghc doc only give the example for non-recursive data like below.
> data T a b = C1 a b | C2 deriving (Typeable, Data)
> GHC will generate an instance that is equivalent to
> instance (Data a, Data b) => Data (T a b) where
> gfoldl k z (C1 a b) = z C1 `k` a `k` b
> gfoldl k z C2 = z C2
> gunfold k z c = case constrIndex c of
> 1 -> k (k (z C1))
> 2 -> z C2
> toConstr (C1 _ _) = con_C1
> toConstr C2 = con_C2
> dataTypeOf _ = ty_T
> con_C1 = mkConstr ty_T "C1"  Prefix
> con_C2 = mkConstr ty_T "C2"  Prefix
> ty_T = mkDataType "Module.T" [con_C1, con_C2]
> Haskell mailing list
> Haskell at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell