monadfix / named

Named parameters (keyword arguments) for Haskell
Other
92 stars 5 forks source link

Add a pattern to get a `Param` from an `:!` #13

Closed JustusAdam closed 6 years ago

JustusAdam commented 6 years ago

I find myself having a function which takes keyword arguments only to pass them onto another function that also takes the same named parameters like so

foo :: "x" :! Int -> ...
foo (Arg x) = bar ! #x x

Would it be possible to add a view pattern (or pattern synonym) that transforms an :! to a Param, lets call it retain for now.


foo :: "x" :! Int -> ...
foo (retain -> x) = bar ! x
int-index commented 6 years ago

Hm-m-m. When I added Param I did not realise that it would make pass-through more complicated. With named-0.1 you could just do this:

foo :: Int `Named` "foo" -> ...
foo x = bar ! x

Now in named-0.2 there's this Param wrapper so it no longer works... I need to think of a good solution, but for now I can suggest using an internal constructor as a temporary workaround:

import Named.Internal (Param(Param))

foo :: "x" :! Int -> ...
foo (Param -> x) = bar ! x
JustusAdam commented 6 years ago

Okay, thanks. 😃

int-index commented 6 years ago

No problem! Reopen if the suggested solution doesn't work

JustusAdam commented 6 years ago

It does. I chose to use a smart constructor though, to make it more future proof.

named :: name :! a -> Param (name :! a)
named = Param

foo :: "x" :! Int -> ...
foo (named -> x) = bar ! x