purescript-deprecated / purescript-generics

21 stars 20 forks source link

Generic1 #14

Open paf31 opened 9 years ago

paf31 commented 9 years ago

Not sure how simple this. Maybe something like

class Generic1 f where
  toSpine1 :: forall a. f a -> GenericSpine
  fromSpine1 :: forall a. GenericSpine -> Maybe (f a)
  toSignature1 :: Proxy1 f -> GenericSignature1

where GenericSignature1 adds a constructor for the type argument somehow.

With a view to deriving Functor, Foldable, Traversable, etc.

gbaz commented 9 years ago

I have a hunch we can derive those without a new class.

In particular, introduce a "fresh type" Placeholder that instantiates generic and is essentially a newtype for unit.

Now you can examine the Spine of Foo Placeholder and see the "shape of Foo with an arbitary placeholder" and work from there...?

paf31 commented 9 years ago

Ah, neat idea.