(I'm not using PS for that long, so bear with me if I'm missing something or this solution is actually common)
Trying to write wrappers around functions taking lots of named arguments (using array), I was wondering whether it would be possible to use something more elegant than bunch of functions in an array to handle them - I've seen some people using Record.union/Record.merge, but trying that, I quickly ran into inference issues that I can't that easily overcome in PS (in HS I would use type equalities on custom typeclass to "trap" label into proper type). At the end, there turned out to be one simple solution - function...
where required and optional are corresponding arguments, I can keep inference happy by updating existing fields instead of trying to match some in separate records. Now, great thing about PS are it's underscore-based sections, and using record update section I can get this pretty syntax
foo_{a=b,c=d,..}
instead of
foo[X.ab,Y.cd,..]
without any name clashes and without possibility of duplicate fields
I don't really have good example to show right now, but I've basically started bolting Fomantic UI on top of normal html from Halogen (https://pursuit.purescript.org/packages/purescript-halogen/5.0.0/docs/Halogen.HTML.Elements) with some custom parameters
Oh, one fix - {| required } -> ({| optional } -> {| optional }) -> _ (record updates can't introduce new fields, and using insert would defeat the purpose of while thing)
(I'm not using PS for that long, so bear with me if I'm missing something or this solution is actually common)
Trying to write wrappers around functions taking lots of named arguments (using array), I was wondering whether it would be possible to use something more elegant than bunch of functions in an array to handle them - I've seen some people using
Record.union
/Record.merge
, but trying that, I quickly ran into inference issues that I can't that easily overcome in PS (in HS I would use type equalities on custom typeclass to "trap" label into proper type). At the end, there turned out to be one simple solution - function...More specfically, taking function
instead of merging with some
where
required
andoptional
are corresponding arguments, I can keep inference happy by updating existing fields instead of trying to match some in separate records. Now, great thing about PS are it's underscore-based sections, and using record update section I can get this pretty syntaxinstead of
without any name clashes and without possibility of duplicate fields
I would love to see a full example
I don't really have good example to show right now, but I've basically started bolting Fomantic UI on top of normal html from Halogen (https://pursuit.purescript.org/packages/purescript-halogen/5.0.0/docs/Halogen.HTML.Elements) with some custom parameters
Oh, one fix -
{| required } -> ({| optional } -> {| optional }) -> _
(record updates can't introduce new fields, and usinginsert
would defeat the purpose of while thing)I may be misreading your requirements, but would this do the job for named optional arguments?
https://pursuit.purescript.org/packages/purescript-option
Yeah, technically, though I'm going for the most compact solution and these seem to be slightly more verbose
@miles woah I hadn't seen that before. I didn't know that was possible. that's really cool.
ah man, do I need to use bower in order to use it?
Looks like it's not yet in the package set, but you can add it as an "addition" in spago. https://github.com/purescript/spago/#add-a-package-to-the-package-set
I tried to clone it and run it with spago to see the docs for version 2 and it didn't work. so I'm not sure if it's that simple.
I didn't try the version that's on pursuit though, maybe that one would work.
yeah, checking out
v1.0.1
(version on pursuit) and runningfails to compile