Skip to content

Instantly share code, notes, and snippets.

@robkuz
Last active August 11, 2022 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robkuz/c2ce150b104e8c56e3f0b6580fede7ea to your computer and use it in GitHub Desktop.
Save robkuz/c2ce150b104e8c56e3f0b6580fede7ea to your computer and use it in GitHub Desktop.
Some thoughts on Purescript Tuples, Records and Dict
--The only way to create what other languages call a **Dictionary** Is to create a `Array (Tuple String a)`.
--This is excessively lengthy (imo). Specifically as the change to 0.7 also removed the Haskell Tuple syntax.
--example
d = [Tuple "x1" 1, Tuple "x2" 2, Tuple "y1" 3, Tuple "y2" 4]
-- prior t0 0.7 you could at least do it this way
d = [("x1", 1), ("x2", 2), ("y1", 3), ("y2", 4)]
-- the problem with the above however is that it is possible to assign the same "label" multiple times.
-- Records on the other hand check for the occurance of the same label and you get a compile time error.
d = {x1: 1, x2: 2, y1: 3, y2: 4m}
-- so all of this much shorter AND compile time checked as well.
-- How sweet!
@hdgarrood
Copy link

Also, I don't think PureScript ever had Haskell-like tuple syntax. Maybe you're confusing it with Elm? See this pull request, for instance, which was opened in August 2014, and which would have added tuples to the language (had it not been closed): purescript/purescript#556.

@hdgarrood
Copy link

(Reposting accidentally deleted comment:)

You can use /\ from Data.Tuple.Nested:

Map.fromFoldable ["x1" /\ 1, ... ]`

@robkuz
Copy link
Author

robkuz commented Apr 25, 2016

oh! just seeing all these good comments. thx.
yeah the infix operator makes it a bit nicer indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment