Skip to content

Subclassing in the Category hierarchy #952

Closed

Description

@laMudri

Currently, the Category hierarchy principally contains the definitions RawFunctor, RawApplicative, and RawMonad. The RawMonad module contains a definition rawApplicative, showing that from a RawMonad, one can get a RawApplicative. In turn, the RawApplicative module contains a definition rawFunctor. Furthermore, the members of rawApplicative and rawFunctor are reexported, meaning that RawMonad exports definitions of _<$>_, pure, and _⊛_.

These exported definitions are defined in terms of return and _>>=_. This means that often, a user will write implementations for all three structures, but their RawFunctor will have a definitionally different implementation of _<$>_ than their RawMonad gives rise to.

It is perhaps useful to be able to derive functors and applicatives just from the monad data, but it also causes problems. There needs somewhere to be a definition of RawMonad containing a RawApplicative field, which itself contains a RawFunctor field. This would provide more coherence to the hierarchy.

Activity

  1. modified the milestones: v1.2, v2.0 on Oct 20, 2019
  2. MatthewDaggitt commented on Sep 12, 2022

    @MatthewDaggitt
    Collaborator

    So the non-indexed versions should not be defined in terms of the indexed ones.

  3. gallais commented on Sep 27, 2022

    @gallais
    Member

    I've started working on this. I'm tempted to additionally drop the exotic unicode combinators for Applicative and
    Alternative in favour of their haskell counterparts.

  4. gallais commented on Sep 27, 2022

    @gallais
    Member

    Hmmm this is really annoying.

    In #636 I defined MonadZero and MonadPlus by combining Monad with
    ApplicativeZero and Alternative respectively. But now that Monad packs
    an Applicative, we have a diamond problem with two potentially unrelated
    instances of Applicative contained in each.

    But rolling back #636 to have once more duplicated empty and _<|>_ in
    both the applicative & monad hierarchies is not really satisfactory as we'll
    really easily get ambiguities.

    So what I'm considering is a parallel hierarchy with records packing empy : F A
    alone first and combined with _<|>_ : F A -> F A -> F A second.

    But I need names for these.
    Let's say Empty & Sum as placeholder for now

    Empty = empty
    Sum = Empty + _<|>_
    
    ApplicativeZero = Applicative + Empty
    Alternative = Applicative + Sum
    
    MonadZero = Monad + Empty
    MonadPlus = Applicative + Sum
    

    Intuitively I was thinking Pointed for Empty but from what I can read for functors
    it's A -> F A rather than F A (even though for sets it's 1 -> X!).

  5. JacquesCarette commented on Oct 1, 2022

    @JacquesCarette
    Collaborator

    My long-term bias definitely is to structure things as per this suggestion, with empty : F A first, then combined with _<|>_.

    Pointed is a confusing thing. Pointed objects are quite different from pointed endofunctors. And it's not quite "has a point".

    I'm not seriously suggesting this, but element-less is closer than empty. But let's not even consider names for the method, just for the record. Try as I might, I can't improve on Empty. However, I think Sum is misleading. I'd prefer Choose or Choice. Choice is likely better. There might be better still.

  6. added a commit that references this issue on Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions