3 ms·
Haskell: case x of _ -> True is a valid expression of type boolean for all values of `x`. if b then True else False is a valid expression if `b` is
by lalaithion 8y ago
Haskell:
case x of _ -> True
is a valid expression of type boolean for all values of `x`.
if b then True else False
is a valid expression if `b` is a boolean.
These can be nested recursively infinitely, but that's not very interesting, so let's move on.
let x = z in y
this is another valid expression for any y and z values.
do e
this is a valid expression if e is a type that implements the Monad typeclass.
Basically every other keyword is for type declarations or module importing, and those both aren't expressions, and seem much harder.
So, my final expression is:
let x = x in do case if let x = x in True then False else False of _ -> return False
where `in do case if let` is my longest expression.
- lelf 8y ago> do e > this is a valid expression if e is a type that implements the Monad typeclass. That is not necessary, do do do ()
- victorNicollet 8y agoGiven the rule: expr := 'if' expr 'then' expr 'else' expr An expression may start with a sequence 'if if if if ...' of arbitrary length (and will contain that same number of 'then' and 'else' keywords, although not as a sequence).
- FBT 8y agoA simpler variation of the same concept is to use the fact that for every expression `expr`, `do expr` is a valid expression, allowing you to start a sequence with any number of `do`s. But the challenge as I see it is to stack as many distinct keywords in a row. In javascript you can do the same thing with `await`: for every expression `expr`, `await expr` is a valid expression, so you can start with a sequence of any number of `await`s. That's great, but ultimately not a challenge: the real puzzle is in stacking as many unique keywords as possible.
- FBT 8y agoYou can add `infixl` or `infixr` to that: let x = x in do case if let infixr 7 `x`; x = x in True then False else False of _ -> return False And with the RecursiveDo extension, you can throw `mdo` in there: let x = x in mdo do case if let infixr 7 `x`; x = x in True then False else False of _ -> return False That brings us to `in mdo do case if let infixr` as the longest string of consecutive (distinct) keywords that I can come up with in Haskell.
- majewsky 8y ago> where `in do case if let` is my longest expression. Not every string of tokens is an expression.