I'm trying to implement simple parser in haskell using parsec
library (for learning purposes). So I wrote bunch of data structutes and related functions like this:
data SourceElement
= StatementSourceElement Statement
| FunctionSourceElement FunctionName FunctionBody
data Statement
= IfStatement Expr Statement Statement
| WhileStatement Expr Statement
data FunctionBody = FunctionBody [SourceElement]
parseSourceElement :: Parser SourceElement
parseSourceElement = ...
parseFunctionBody :: Parser FunctionBody
parseFunctionBody = ...
It works fine. Now I want to split this stuff into two modules to separate FunctionBody
and Statement
data structures (because of readability issues). But I can't! The reason is cyclic dependency between SourceElement
and FunctionBody
.
So, is there any way to solve this problem ?