DeepSeq

Ralf Hinze ralf@informatik.uni-bonn.de
Fri, 19 Jul 2002 14:04:45 +0200


> Beeing able to derive instances of DeepSeq would be nice too.

Here is an implementation using GHC's derivable type classes.

Cheers, Ralf

----

ghc -c -fglasgow-exts -fgenerics -package lang Eval.lhs

> module Force
> where
> import Generics

> class Force a where
>   force=09=09=09:: a -> ()
>
>   force{|Unit|} a=09=09=3D  a `seq` ()
>
>   force{|b :+: c|} a=09=09=3D  case a of
>=09=09=09=09     Inl b -> force b
>=09=09=09=09     Inr c -> force c
>
>   force{|b :*: c|} a=09=09=3D  case a of
>=09=09=09=09     b :*: c -> force b `seq` force c
>
> instance Force Char where
>   force a=09=09=09=3D  a `seq` ()
> instance Force Int where
>   force a=09=09=09=3D  a `seq` ()

> eval=09=09=09=09:: (Force a) =3D> a -> a
> eval a=09=09=09=3D  force a `s