This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Consider a data type representing syntax trees. | |
| > data Expr = BinOp Expr Expr | Unop Expr | |
| > data Stmt = Seq Stmt Stmt | Assign String Expr | |
| Let's say I want this in a module, but I also want to be able to arbitrarily extend this AST type | |
| in modules that import it. So, I add an extra constructor and a type parameter | |
| to all the data type definitions: | |
| > data Expr ext = BinOp (Expr ext) (Expr ext) | Unop (Expr ext) | Ext ext |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| > {-# LANGUAGE QuasiQuotes #-} | |
| > {-# LANGUAGE EmptyDataDecls #-} | |
| > import Control.Comonad | |
| > import Language.Haskell.Codo | |
| > data Input a | |
| > data Output a | |
NewerOlder