-
Notifications
You must be signed in to change notification settings - Fork 37
Closed
Labels
Description
This is a simpler kind of stack machine based rendering, when all we’re concerned about is printing output, pushing and popping based on certain SimpleDoc constructors. This won’t allow fancy stack machines that peek, double-push and what not.
e.g. annotated-wl-pprint contains:
displayDecoratedA :: (Applicative f, Monoid b)
=> (String -> f b) -> (a -> f b) -> (a -> f b)
-> SimpleDoc a -> f b
displayDecoratedA str start end sd = display [] sd
where display [] SEmpty = pure mempty
display stk (SChar c x) = (str [c]) <++> (display stk x)
display stk (SText l s x) = (str s) <++> (display stk x)
display stk (SLine ind x) = (str ('\n':indentation ind)) <++> (display stk x)
display stk (SAnnotStart ann x) = (start ann) <++> (display (ann:stk) x)
display (ann:stk) (SAnnotStop x) = (end ann) <++> (display stk x)
-- malformed documents
display [] (SAnnotStop _) = error "stack underflow"
display stk SEmpty = error "stack not consumed by rendering"
(<++>) = liftA2 mappend
Convinced this is a good idea in #12.