Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: hoistM and toList/fromList #43

Closed
NCrashed opened this issue Jul 11, 2018 · 5 comments

Comments

@NCrashed
Copy link

commented Jul 11, 2018

Hi, I would like to have additional helpers for the library:

-- Usecase: operations with map in custom monads
hoistM :: Applicative t => (forall x. f x -> t (g x)) -> TypeRepMap f -> t (TypeRepMap g) 

-- I don't sure that code below is the best design, but it should represent the main idea 
-- Usecase: serelisation/deserialisation for aeson 
newtype Wrapper f = Wrapper { unWrapper :: forall x . f x }
toList :: TypeRepMap f -> [Wrapper f]
fromList :: [Wrapper f] -> TypeRepMap f
@int-index

This comment has been minimized.

Copy link
Collaborator

commented Jul 11, 2018

We already have fromList: https://hackage.haskell.org/package/typerep-map-0.1.0/docs/Data-TypeRepMap-Internal.html#v:fromList

I guess we only need a better name for TF.

And instead of exporting toList and fromList as separate combinators, we could define an https://hackage.haskell.org/package/base-4.11.1.0/docs/GHC-Exts.html#t:IsList instance.

An IsList instance would have several advantages:

  • We'd get the [] syntax with -XOverloadedLists, so one could write [TF a, TF b, TF c] :: TypeRepMap f
  • We get an opportunity to implement fromListN more efficiently by preallocating vectors of the specified size.
@int-index

This comment has been minimized.

Copy link
Collaborator

commented Jul 11, 2018

As to hoistWithM, I agree with the type signature you propose.

@chshersh

This comment has been minimized.

Copy link
Member

commented Jul 11, 2018

@int-index Why the name is hostWithM? Maybe it should be hoistWithA and also create function with Monad constraint instead of Applicative?

@int-index

This comment has been minimized.

Copy link
Collaborator

commented Jul 11, 2018

The name doesn't matter, it can be hoistWithA if you want. I see no reason to add a Monad-specific version.

@int-index

This comment has been minimized.

Copy link
Collaborator

commented Jul 11, 2018

Sorry, I actually meant hoistM and hoistA, the With suffix is unnecessary.

@chshersh chshersh closed this in #44 Jul 27, 2018
chshersh added a commit that referenced this issue Jul 27, 2018
* Put fromList into IsList instance

* Implement IsList instance

Rename TF to WrapTypeable
Add keys field to TypeRepMap

* Fix TypeRep, Add hoistA function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.