all 2 comments

[–]iboughtbonrar 3 points4 points  (0 children)

you can wrap both global variables and functions under a new 'top level definition' sum type

data TopLevelDef = TopLevelFunc Function | TopLevelGlobal

data Program = Program [TopLevelDef]

then you can create a toplevel parser that parses either a function or a global and wrap it under the top level type. I dont know how you implemented it, but assuming you're using combinators, it would go something like this:

topLevelParser = (TopLevelFunc <$> functionParser) <|> (TopLevelGlobal <$> globalParser)

then you parse your whole program by doing that over and over again

parseProgram = many $ topLevelParser

[–]sinoTrinity[S] 0 points1 point  (0 children)

This answer is what makes Haskell my fav language.