Skip to content

Pattern matching on data constructors with Rank N functions #42

@fxdpntthm

Description

@fxdpntthm
newtype NT m a = MkNT {unNT :: forall b. a -> m b}

foobar1 :: (b -> a) -> NT m a -> NT m b
foobar1 f nt = MkNT $ \ a -> unNT nt (f a)

foobar2 :: (b -> a) -> NT m a -> NT m b
foobar2 f (MkNT nt) = MkNT $ \ a -> nt (f a)

Although they both should work, foobar1 doesn't. The use of unNT gives rise to a wanted m @ b constraint.
one could type foobar1 :: Total m => (b -> a) -> NT m a -> NT m b. The total constraint is needed here as m as it can be applied to any b

Metadata

Metadata

Assignees

No one assigned

    Labels

    Low PriorityThings that are good to have but not needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions