Continuation of this comment.
@Adrielus you make a good point.
@ajnsit you also make a good point. I know that PureScript’s syntax is almost the same as Haskell’s, but is having a similar syntax a goal of PureScript?
Continuation of this comment.
@Adrielus you make a good point.
@ajnsit you also make a good point. I know that PureScript’s syntax is almost the same as Haskell’s, but is having a similar syntax a goal of PureScript?
In my personal opinion - I am not too bothered by the extra commas. Particularly when formatted like this -
foo =
[ someValue
, anotherValue
, finalValue
]
It’s a very minor inconvenience to prefix the first value with a [
and subsequent values with ,
but it’s not enough to change syntax.
Haskell libraries often abuse the monadic do-notation to append values together.
FWIW I hacked together an example in Purescript - https://try.purescript.org/?gist=f714e9f5b58b5f705b661c02eb929f47. Open the browser console to see the output.
It allows code like this -
foo = unwrap do
e someValue
e anotherValue
e finalValue
It’s still terrible (because >>
is not a part of the Monad class, and ado
has a different syntax), but atleast it gets rid of the commas!
EDIT: To clarify my stance, this is a bad idea, please don’t use this in production.
I’m going to pretend I didn’t see that.
Jokes aside, I agree with you.
To be clear, in F#, when elements are on separate lines, seperators are optional, so the following would all be valid
let bs = [
1
2
3
]
let cs = [ 1; 2; 3 ]
let ds =
[ 1
; 2
; 3
]
let es =
[ 1; 2
3; 4 ]
So I don’t think it pulls away from Haskell syntax much to use the same strategy, since the Haskell syntax is still valid, it just adds more options. However, IMO I agree it’s not worth the effort of the core maintainers to implement something like that.
As an amusing anecdote, my team uses F# on the backend and PureScript on the frontend, and several of my fellow developers have started defining records & lists using the syntax like
let ds =
[ 1
; 2
; 3
]
for multiline definitions, just because they picked it up from PureScript and liked it so much
Ah, you can do optional separators with this as well, just use *>
as the separator For example the following would be an array [2,3,4,5,6]
-
unwrap do
e 2 *> e 3
e 4 *> e 5
e 6
There is implicit intuititive semantics to the structuring in lines, indents, and spaces that is being paved over by what seems to be tradition. F# code make for a fluid specification language as well as executable code at the high levels (its lack of type classes and binding to .Net does hobble it). For example,
let myList = [
pow 1.3 8.6
sqrt 2
Math.PI
23.67
sum [
3.0
5.7
234.87
]
]
One other curiosity of Purescript to my novice eyes is the class definition weird use of, <=
. Why not stick to =>
for all dependency flow relationships together with the use of parenthesis when you have more than one constraint.