Skip to content

Instantly share code, notes, and snippets.

@merbjedi
Created November 10, 2009 10:37
Show Gist options
  • Select an option

  • Save merbjedi/230792 to your computer and use it in GitHub Desktop.

Select an option

Save merbjedi/230792 to your computer and use it in GitHub Desktop.
p_term :: Parser Term
p_term = t <* spaces
where
t = IntTerm <$> p_num (readSigned readDec)
<|> FloatTerm <$> p_num (readSigned readFloat)
<|> AtomTerm <$> p_atom
<|> TupleTerm <$> p_tuple
<|> BytelistTerm . C.pack <$> p_string
<|> ListTerm <$> p_list
<|> BinaryTerm . B.pack <$> p_binary
Again, reading very naturally: a term is t possibly followed by some whitespace. (a <* b means roughly “run a, then b, but the value of the expression is the value of a”). t in turn can be either a p_num wrapped with an IntTerm, and so forth. (In this context, <|> can very roughly be thought of as “otherwise, try..” and <$> as “wrap the results of the argument to the right with the thing on the left”.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment