hackett
hackett copied to clipboard
Feature: implied parentheses
Since this is 21'th century, we probably can have many (most?) parentheses implied, in a way that is not dissimilar to how Haskell does implicit { ... }
blocks (which people mostly don't use for a couple of reasons that are not directly relevant here, since the tradeoffs are different, because no macros).
To be precise: the idea is to allow BOTH options (as in Haskell), since:
- We still need to allow the fully-parenthesised form to be emitted in macros, where you really really want to be specific about the parentheses.
- The long, multi-line expression cases still stand
To consider the difference of presentation -- using the example from the README:
#lang hackett
data Maybe a
nothing
just a
def x : Int
let y 3
z 7
y + z
class Show a
show : Int -> a -> String
instance forall [a] (Show a) => Show (Maybe a)
def+ show
nothing -> "nothing"
just x -> "just " <> show x
..versus:
#lang hackett
(data (Maybe a)
nothing
(just a))
(def x : Int
(let ([y 3]
[z 7])
{y + z}))
(class (Show a)
[show : {Int -> a -> String}])
(instance (forall [a] (Show a) => (Show (Maybe a)))
(def+ show
[nothing -> "nothing"]
[(just x) -> {"just " <> (show x)}]))
As a personal perspective -- after a long time of doing Lisp, and then coming to Haskell, I have come to value its visual terseness.
It seems to increase the raw perception bandwidth.
I agree that this would be nice if it could be done perfectly, but it’s trickier in practice than it might seem. I do think it would be cool to have an opt-in ML-like reader that you could get with #lang hackett/ml
or something like that. For prior art, check out the following SRFIs:
- SRFI 49: Indentation-sensitive syntax
-
SRFI 110: Sweet-expressions — This one has an existing Racket implementation that works with arbitrary
#lang
s that use the Racket reader, including (as of now) Hackett. - SRFI 119: wisp
The fact that there are three different standards for this hints that this is a harder problem than it might seem. I would encourage you to study the different tradeoffs each of them makes to better understand what the challenges are.
While I agree that Haskell-like syntax may be easier on the eyes for some, I doubt that the individual perception bandwidth is increased all that much. And the parentheses are not only useful for macros but for editors' structural editing capabilities (which can be thought of as development-time [i.e., pre-compile time] key-bound macros).