by lalaithion · 7y ago · 0 comments
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. 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. 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).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.
That is not necessary,
do do do ()Not every string of tokens is an expression.