[Haskell] How to define gunfold on List?
José Pedro Magalhães
jpm at cs.uu.nl
Sun Jan 18 04:56:53 EST 2009
Hi there,
There's no difference. See
http://hackage.haskell.org/packages/archive/base/4.0.0.0/doc/html/src/Data-Data.html#line-1034
You can also see many other instances there.
Cheers,
Pedro
On Sun, Jan 18, 2009 at 10:50, haihualin <haihualin at 163.com> wrote:
> Hi,
>
> Does some one know how to define gunfold on recursive data struction like
> List?
>
> 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
> http://www.haskell.org/mailman/listinfo/haskell
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell/attachments/20090118/61c3510e/attachment.htm
More information about the Haskell
mailing list