1
\$\begingroup\$

I am trying to implement the data type LExpr as an instance of show.

data LExpr = Var String        
                | App LExpr LExpr   
                | Lam String LExpr 

This is my code:

 instance Show LExpr where
      showsPrec d (Var str)   = showString' str
      showsPrec d (App e1 e2) = showParen (d>=6) $ showsPrec 6 e1  . showString " " . showsPrec 5  e2
      showsPrec d (Lam str e) = showParen (d>=5) $ showString ("\\"++str++" -> ") . showsPrec 5 e

I am looking for some advice on how to further improve my code.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.