Right now we store the user's project as a Markdown file with some options on top so inliterate can render it properly. The thing is that this is not really efficient, because if the user were to use the project as a library on a production system, they would have to drag inliterate and all of its dependencies with them. So, we can do something "intelligent" with it:
When the user works within Haskell.do, everything gets stored in a regular (no inliterate) Lib.hs Haskell file, replacing Haskell.do blocks like this:
Everything that is text (except code) gets stored as a multiline comment, for example:
I'm text
` ` ` haskell top
im :: Code
im = undefined
` ` `
I'm text too,
but
multiline
Would get stored as:
{-I'm text-}
im :: Code
im = undefined
{-I'm text too
but
multiline-}
Same with haskell eval and haskell do blocks. These are for exploration, and in the end they are just comments on steroids that we use to explain things, the only difference that they would be stored like:
{- haskell eval
2 + 2 -}
{- haskell do
x <- readFile "foo" -}
The placement of the braces is important, because it allows us to have the same line numbers
See where this is going? Now, the user can safely remove the inliterate dependency from their project without having to worry about that (unless they are using it in their library functions of course).
So, how do we render everything? Easy, when we compile the project, we generate a Main.hs file with the format that inliterate expects. This is great because of two things:
First, we decouple inliterate from the user, which is counter-productive
Second, we can generate a source map, so we can highlight errors
The second point is very important, as right now the output of GHC for errors is quite random for us, because inliterate generates the boilerplate required to render everything, so this way we could parse the error strings and highlight the errors on the document.
Right now we store the user's project as a Markdown file with some options on top so
inliterate
can render it properly. The thing is that this is not really efficient, because if the user were to use the project as a library on a production system, they would have to draginliterate
and all of its dependencies with them. So, we can do something "intelligent" with it:When the user works within Haskell.do, everything gets stored in a regular (no inliterate)
Lib.hs
Haskell file, replacing Haskell.do blocks like this:Everything that is text (except code) gets stored as a multiline comment, for example:
Would get stored as:
Same with
haskell eval
andhaskell do
blocks. These are for exploration, and in the end they are just comments on steroids that we use to explain things, the only difference that they would be stored like:The placement of the braces is important, because it allows us to have the same line numbers
See where this is going? Now, the user can safely remove the
inliterate
dependency from their project without having to worry about that (unless they are using it in their library functions of course).So, how do we render everything? Easy, when we compile the project, we generate a
Main.hs
file with the format thatinliterate
expects. This is great because of two things:inliterate
from the user, which is counter-productiveThe second point is very important, as right now the output of GHC for errors is quite random for us, because
inliterate
generates the boilerplate required to render everything, so this way we could parse the error strings and highlight the errors on the document.