TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Haskell RecordDotSyntax language extension proposal (Accepted)

179 pointsby harporoederover 4 years ago

15 comments

hardwaresoftonover 4 years ago
For those that want to see what it actually looks like:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;ghc-proposals&#x2F;ghc-proposals&#x2F;blob&#x2F;master&#x2F;proposals&#x2F;0282-record-dot-syntax.rst#examples" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ghc-proposals&#x2F;ghc-proposals&#x2F;blob&#x2F;master&#x2F;p...</a><p><pre><code> data Grade = A | B | C | D | E | F data Quarter = Fall | Winter | Spring data Status = Passed | Failed | Incomplete | Withdrawn data Taken = Taken { year :: Int , term :: Quarter } data Class = Class { hours :: Int , units :: Int , grade :: Grade , result :: Status , taken :: Taken } getResult :: Class -&gt; Status getResult c = c.result -- get setResult :: Class -&gt; Status -&gt; Class setResult c r = c{result = r} -- update setYearTaken :: Class -&gt; Int -&gt; Class setYearTaken c y = c{taken.year = y} -- nested update getResults :: [Class] -&gt; [Status] getResults = map (.result) -- selector getTerms :: [Class] -&gt; [Quarter] getTerms = map (.taken.term) -- nested selector</code></pre>
评论 #24543430 未加载
评论 #24542182 未加载
评论 #24545436 未加载
gregwebsover 4 years ago
Simon Peyton Jones: &quot;One possible reaction to a diversity of opinion is to do nothing and wait for clarity to emerge. That is often the right choice, but not (I believe strongly) in this case. We have waited a long time already -- I have been engaged in debate about this topic for over two decades -- and I think it&#x27;s time to decide something.&quot;
评论 #24539669 未加载
评论 #24539609 未加载
moonchildover 4 years ago
Possibly recommend changing link to the proposal itself[1]?<p>Both pages link to each other, but the discussion is unlikely to be of very much note unless one has already read the proposal being discussed.<p>1. <a href="https:&#x2F;&#x2F;github.com&#x2F;ghc-proposals&#x2F;ghc-proposals&#x2F;blob&#x2F;master&#x2F;proposals&#x2F;0282-record-dot-syntax.rst" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ghc-proposals&#x2F;ghc-proposals&#x2F;blob&#x2F;master&#x2F;p...</a>
hopiaover 4 years ago
Nothing is better than seeing the broken pieces of the foundation fixed in Haskell.<p>Records were my number one gripe in the language that otherwise does so many advanced things so uniquely well.
评论 #24540409 未加载
ben509over 4 years ago
It looks sane and solidly specified. I never trusted DisambiguateRecordFields, so I&#x27;ll finally ditch a lot of ugly prefixes I stuck in there.<p>The whitespace requirements, though, are going to lead to some confusing error messages for newbies who want to type myRecord . someField
评论 #24539215 未加载
评论 #24539233 未加载
imdoorover 4 years ago
Does the proposal have any effect on lens usage?<p>EDIT: I mean, lenses and RecordDotSyntax both provide a way to access nested fields in records, so the new syntax would take away some of the reasons to use lenses. But are there any other relations among the two, or do lenses and RecordDotSyntax just provide two different solutions to the same problem?
评论 #24540684 未加载
bweitzmanover 4 years ago
Wow this is great! Fixing Haskell&#x27;s arcane record system would be a huge step towards more mainstream adoption. It was certainly my largest pain point with the language over years of use in production.
评论 #24540433 未加载
jakubobozaover 4 years ago
Imho this looks good. It will save on key strokes and maybe bring more readability. I always liked &quot;.&quot; or &quot;-&gt;&quot; syntax in different languages.<p>My only worry is . being function composition operator so it might not be crazy amazing for readability only you get<p>a . b . c . d.e<p>So maybe it should have been something like &quot;-&gt;&quot;.
评论 #24545362 未加载
评论 #24543004 未加载
TazeTSchnitzelover 4 years ago
PureScript, which borrows heavily from Haskell&#x27;s syntax (you could say it is Haskell for JavaScript but with strict evaluation) already had something like this for syntax for accessing records (JS objects). It wisely didn&#x27;t also use the dot for function composition however. I hope it will be the norm to use some alias other than (.) for function composition when this extension is used.
评论 #24542176 未加载
评论 #24543297 未加载
tartrateover 4 years ago
How did Idris solve this again btw?
评论 #24557819 未加载
pbiggarover 4 years ago
The syntax to update records doesn&#x27;t seem particularly nice:<p><pre><code> e{lbl = val} </code></pre> Though this has been a part of haskell for a while it seems:<p>&gt; Note: e{lbl = val} is the syntax of a standard H98 record update<p>FSharp, OCaml and Elm have not got great solution here either:<p><pre><code> { e with lbl = value } &#x2F;&#x2F; ocaml&#x2F;fsharp { e | lbl = value } </code></pre> Do any functional languages have anything as nice as:<p><pre><code> e.lbl = value</code></pre>
评论 #24542120 未加载
评论 #24542056 未加载
评论 #24542216 未加载
评论 #24543342 未加载
评论 #24543982 未加载
评论 #24542132 未加载
评论 #24542141 未加载
评论 #24544262 未加载
评论 #24543730 未加载
singularity2001over 4 years ago
Where can one track the progress of the implementation and be informed when it&#x27;s ready?
评论 #24541620 未加载
AzzieElbabover 4 years ago
... and if stick a lambda in there the whole thing becomes on object :)
johndoe42377over 4 years ago
As record slot&#x27;s value retrieval (I love old lisp terminology) could be viewed as a pure function (given the record as a parameter) it is reasonable to think of .slot as a function.<p>The old classic languages just create so-called selectors in the global namespace, like defstruct macro does. This is not the best possible solution.<p>However, the . is used for function composition, so the better alternative could be the -&gt; syntax, reflecting that in Haskell everything is a pointer.
评论 #24550568 未加载
srtjstjsjover 4 years ago
What&#x27;s sad is that only reason this situation is so controversial is because all of programming language design is constrained by the 19th Century typewriter keyboard.
评论 #24544428 未加载