Skip to content

Make types more flexible #11

@treeowl

Description

@treeowl

I realized in coercible-utils #14 that the inference-enhancing effects of the O type are only needed for some of the arguments. For the rest, things can be left much freer. That suggests a modification here as well:

class Isomorphic n o where
  packI   :: o -> n
  default packI :: (Generic n, GNewtype (Rep n), O n ~ GO (Rep n), o ~ O n) => o -> n
  packI = to . gpack

  unpackI :: n -> o
  default unpackI :: (Generic n, GNewtype (Rep n), O n ~ GO (Rep n), o ~ O n) => n -> o
  unpackI = gunpack . from

class Isomorphic n (O n) => Newtype n where
  type O n :: *
  type O n = GO (Rep n)

pack :: Newtype n => O n -> n
pack = packI

unpack :: Newtype n => n -> O n
unpack = unpackI

Now you can use Isomorphic, rather than Newtype, for the type variables that are already constrained by the type of the packer the user passes in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions