@rae: RebindableSyntax in Haskell
Вставка
- Опубліковано 3 січ 2025
- I give an introduction to GHC's RebindableSyntax extension, with examples.
GHC manual page: downloads.hask...
Find me at richarde.dev/ or on Twitter at @RaeHaskell
Video index at richarde.dev/v...
Awesome! Eventually will all of Haskell's syntax be rebindable?
rae casually typed `one,two,three :: Int` in, and I had no idea that was a valid syntax.
Great video! You can also use MonadComprehensions with RebindableSyntax to get custom list comprehension behavior.
I was really surprised how much nicer qualified do felt in practice. Makes me wish for the other features in RebindableSyntax to be more granular and qualifiable as well
It seems like
foo = do
where DoNotation{..} = M.doNotation
should be similar, but it's a lot less mental overhead for me with the prefixes version.
Second surprise that there is no qualifiedDo indexed monad package on hackage yet.
The `ifThenElse` example makes me wish there was a `QualifiedIfThenElse` language extension!
How about overloading whitespace (i.e. function application)?😈
really cool!
tbh this sounds horrible for any kind of reader of the code.
You have to essentially know that the magic language extension is set (it doesn’t stand out), then follow all imports (some might be implicit!) and know all of the magic function names, in order to figure out what any of the code does.
This is an anti-feature!
The alternative is: just use plain old functions.
The code will be easy to read, easy to follow (go to definition works!), not freak out hls, etc etc etc.
Don’t use RebindableSyntax.
RebindableSyntax is not meant for everyday programs. You would only use this if you're working in a really specific setting where you need to override prelude syntax. E.g. you're working with linear or graded monads and would like to use do-notation (pre QualifiedDo).
It seems suitable for making a DSL in haskell though, as long as it is documented I dont see what would be the problem... *as long as it is documented*...