Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record syntax clarification

Tags:

haskell

OK, so here's an unusual one. Every time you see an example of Haskell's record syntax, it always looks like

Sphere {center = 0, radius = 2}

or similar. My question is... are those curly brackets actually part of the record syntax? Or are they actually shorthand for layout? In other words, can you actually write something like

Sphere
  center = 0
  radius = 2

and have it work?

I doubt it would be very useful to do this - it takes up a lot of visual space - but I'm just curious as to whether this is syntactically valid or not.

like image 600
MathematicalOrchid Avatar asked Jul 23 '26 01:07

MathematicalOrchid


1 Answers

Layout is an alternative to explicit braces and semicolons.

Record syntax uses explicit braces and commas.

So no, you can't use layout as part of record syntax.

Haskell Report 2010 §2.7 Layout:

Haskell permits the omission of the braces and semicolons used in several grammar productions, by using layout to convey the same information.

like image 71
dave4420 Avatar answered Jul 25 '26 21:07

dave4420



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!