emilaxelsson / syntactic

Generic representation and manipulation of abstract syntax
BSD 3-Clause "New" or "Revised" License
25 stars 13 forks source link

Forcing Evaluation of an AST #21

Closed crockeea closed 9 years ago

crockeea commented 9 years ago

What's the best way to force evaluation of an AST? I tried to define an NFData instance (from Control.Deepseq) for AST dom a, but the existential types in the constructors cause problems. Is there any hope for an NFData instance? What about other ways to ensure that the tree is fully evaluated?

emilaxelsson commented 9 years ago

I think you just need an extra class for forcing symbols:

class NFSym sym
  where
    rnfSym :: sym sig -> ()

instance NFSym sym => NFData (AST sym sig)
  where
    rnf (Sym s)  = rnfSym s
    rnf (s :$ a) = rnf s `seq` rnf a