For the extra curious, here's a little Parser (untested, poor design, but generally the right idea)
newtype Parser a = Parser { unParser :: MaybeT (State String) a }
deriving ( Functor, Applicative, Alternative,
Monad, MonadPlus, MonadTrans,
MonadState String )
-- why write boilerplate when the
-- compiler will for you?
runParser :: Parser a -> String -> Maybe a
runParser input = flip evalStateT input . runMaybeT
-- | Parses a single character if it passes a predicate
satisfy :: (Char -> Bool) -> Parser Char
satisfy p = do
(c:cs) <- get
guard (p c)
put cs
return c
char :: Char -> Parser Char
char c = satisfy (== c)
-- | Parses a whole string
string :: String -> Parser String
string = mapM char
-- | Converts a parser to be surrounded by parentheses
parens :: Parser a -> Parser a
parens p = char '(' *> p <* char ')'
The shallow DSL in the LLVM monad is really nice, it looks almost like the IR itself but you can abstract over it and compose it with other code. DSLs are often overlooked when talking about monad use cases.
If you're not curious about haskell, I suspect that parser is going to be very difficult to grok.
At least a basic understanding of haskell (or similar) is going to be required to appreciate it, and at that point you're obviously someone who was curious enough to have the knowledge to understand it to begin with.
A while ago I wrote a Haskell compiler for a simple functional language that uses the JIT features of LLVM in order to make the Haskell-level "compile" function lazy in the term being compiled. Quite a fun trick I thought: https://github.com/batterseapower/productive-compiler/blob/m...
Let's not make this like reddit where there's scores of people who have nothing to do but complain about something they've already seen.
If it's interesting, it's interesting. If it's not worthy of being seen again, it won't be upvoted. By all means link to the previous discussion, but quit the whining.
Comments
Even if you're not curious about Haskell, have a look at the parser here. Parsing in Haskell feels like cheating.
(And is a really great example motivating both monads and monad transformers, for the curious!)
For the extra curious, here's a little Parser (untested, poor design, but generally the right idea)
The shallow DSL in the LLVM monad is really nice, it looks almost like the IR itself but you can abstract over it and compose it with other code. DSLs are often overlooked when talking about monad use cases.
I really need to explore LLVM in more detail at some point.
If you're not curious about haskell, I suspect that parser is going to be very difficult to grok.
At least a basic understanding of haskell (or similar) is going to be required to appreciate it, and at that point you're obviously someone who was curious enough to have the knowledge to understand it to begin with.
A while ago I wrote a Haskell compiler for a simple functional language that uses the JIT features of LLVM in order to make the Haskell-level "compile" function lazy in the term being compiled. Quite a fun trick I thought: https://github.com/batterseapower/productive-compiler/blob/m...
Good job with that trailing /
https://news.ycombinator.com/item?id=7031998Let's not make this like reddit where there's scores of people who have nothing to do but complain about something they've already seen.
If it's interesting, it's interesting. If it's not worthy of being seen again, it won't be upvoted. By all means link to the previous discussion, but quit the whining.
Reddit hasn't been intentionally coded to avoid duplicate submissions.
There are other users that kindly point out prior submissions to highlight past discussions. You're just being unpleasant.
As someone who's interested in Haskell and missed this the first time around, I'm glad it's back.