
4 Jul
2009
4 Jul
'09
12:33 a.m.
Kim-Ee Yeoh wrote:
type VarCount = int newtype Y b a = Y {unY :: VarCount -> (b, VarCount)}
Hi Edward,
Your runPretty version fits the bill nicely, thank you. I might still retain the state monad version because it allows generalizations beyond pretty-printing.
As for fixing the original bug, I've found that the real magic lies in the incantation (Y . unY) inserted at the appropriate places.
Aka unsafeCoerce, changing the phantom type |a|. The need to do it is caused by wanting to erase the existential introduced by Za/MkZa. Depending on what the phantom type is supposed to represent, this may or may not give the semantics/safety you're after. -- Live well, ~wren