Slightly expanding the challenge to include ghc flags.
We can replace both empty lists with typed holes _, saving to 2 characters.
Typed holes aren't a language feature, and are normally (handy) compile errors.
But we can ask GHC to please defer those errors to runtime
with the flag: -fdefer-typed-holes
I think it's important here that those defered errors don't trigger at runtime,
that would be cheating.
But the code runs just as well as before, producing an empty list of integers.
-fdefer-out-of-scope-variables
Allows us to change the id in the ViewPattern to the undefined i,
saving 1 more character.
Oops, I broke my own rule on not having runtime errors.
The first empty list can't be a hole, or the bangpattern will trigger a deferred type error. +1 char
But I forgot the use the unicode → in the view pattern. -1 char
We can eliminate one space by moving the
#
to another position that doesn't need it, before a←
And add two
#
's to the TuppleSection so we useUnboxedTuples
Since our toplevel binder is now just one character we can get its name
instead of
()
, saving 1 characterChange one of the patterns inside the list comprehension to use
ViewPatterns
= 78 characters, requiring 23 language extensions
Use
n+1
as pattern inside the ViewPattern withNPlusKPatterns
= 81 chars, slightly to long :(
But we can move the BinaryLiteral (with NumericUnderscores) to the NPlusKPattern.
And move the HexFloatLiteral to where the BinaryLiteral used to be.
:) 79 chars, 24 exts
Slightly expanding the challenge to include ghc flags.
We can replace both empty lists with typed holes
_
, saving to 2 characters.Typed holes aren't a language feature, and are normally (handy) compile errors.
But we can ask GHC to please defer those errors to runtime
with the flag:
-fdefer-typed-holes
I think it's important here that those defered errors don't trigger at runtime,
that would be cheating.
But the code runs just as well as before, producing an empty list of integers.
-fdefer-out-of-scope-variables
Allows us to change the
id
in the ViewPattern to the undefinedi
,saving 1 more character.
76 chars, 24 language extensions, 2 ghc flags
Wonderful!
Many tricks like this in the Reddit thread too: reddit.com/r/haskell/comments/hzz8...
Oops, I broke my own rule on not having runtime errors.
The first empty list can't be a hole, or the bangpattern will trigger a deferred type error. +1 char
But I forgot the use the unicode
→
in the view pattern. -1 charSo still 76 chars, 24 language extensions, 2 ghc flags