-
Notifications
You must be signed in to change notification settings - Fork 0
Description
A syntax shorthand for applying an operator across many lines could be a suitable replacement for Haskell's do-notation:
main = >> // This syntax is unworkable, as shown later
putStrLn "Who are you?"
K $ getLine
name. putStrLn $ "Hello, " ++ name
// An advantage of this expression-oriented form is that the line above could've been written as
// putStrLn . ("Hello, " ++)
K $ putStrLn "Wow, you have a long name!" <* guard $$ length name > 10
where K = const
The offsides rule is applied to split arguments up, then they are all folded by the provided operator.
Minus functions, that syntax is great:
opt = Options
<$> argument str $$ <>
metavar placeholder
help "Input file"
<*> strOption $$ <>
long "out"
short 'o'
metavar placeholder
help "Output file"
An immediate annoyance is that functions would need to be handled specially. Without, main would be de-sugared to:
(putStrLn "Who are you?")
>> (K $ getLine)
>> (name. putStrLn $ "Hello, " ++ name)
>> (K $ putStrLn "Wow, you have a long name!" <* guard $$ length name > 10)
Where name is unbound in the last argument.
This leads to the unsolvable problem with this syntax in respect to functions. When the parser finds the start of the multiline shorthand, the linearizer has already collapsed all the arguments after name. putStrLn... into its body. The linearizer itself doesn't have the finesse to pick up on the shorthand in sequences like $$ <>. Like where clauses, the shorthand would need to be marked by a keyword.
Other concerns
- Syntax shown only accommodates
a -> a -> afolders. This makes it impossible to construct a list by this syntax. The future form of this syntax must be able to at least construct a list. - Supporting not nesting functions. For the
|operator, I could see not wanting the previous values in the pipeline being available. On the other hand, this would be power given to this sugar that regular expressions would not have.