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

Contravariant hierarchy #10

Open
subttle opened this issue Nov 4, 2019 · 3 comments
Open

Contravariant hierarchy #10

subttle opened this issue Nov 4, 2019 · 3 comments

Comments

@subttle
Copy link
Owner

subttle commented Nov 4, 2019

I think it makes more sense to have a more precise hierarchy for contravariant functors.

  • Separate divide and conquer into two classes?
  • Seperate lose and choose into two classes?
  • Add class to handle These?
  • What about analog for Selective functors?

I need to figure out some laws that should give better guidance. For now, here is some spit-balling. All names here are subject to change.

class (Contravariant f)  Losable f where
  emptied  f Void
  emptied'  (Decidable f)  f Void
  emptied' = lost
  -- `covacuous`?
  empty  f a  f Void
  empty = contramap absurd
class (Decidable f)  RenameMe f where
  renameme  (a  These b c)  f b  f c  f a

renamed  (RenameMe f)  f b  f c  f (These b c)
renamed = renameme id

renamed'  (RenameMe f)  f a  f a  f a
renamed' = renameme (\s  These s s)
@subttle subttle added the idea label Nov 4, 2019
@subttle
Copy link
Owner Author

subttle commented Nov 17, 2019

Experiment:

class Alternative f  Combines f where
  one  f (These a b)  f (a  c)  f (b  c)  f c
class Applicative f  Composes f where
  two  f (These a b)  f (a  b)  f (b  c)  f c
class Alternative f  Selective' f where
  select'  f (Either a b)  f (a  c)  f (b  c)  f c

@subttle
Copy link
Owner Author

subttle commented Dec 23, 2019

Another experiment:

class (Contravariant f) ⇒ MaybeH f where
  maybeh ∷ (a → Maybe b) → f b → f a
instance MaybeH Predicate where
  -- FIXME not sure `False` is the correct default value here
  -- TODO compare with `Either () b` instance?
  -- TODO could also just require `Monoid b` and use `mempty` in place of `False`
  maybeh ∷ ∀ a b . (a → Maybe b) → Predicate b → Predicate a
{-
  maybeh h (Predicate pᵇ) = Predicate pᵃ
    where
      pᵃ ∷ a → Bool
      pᵃ = maybe False pᵇ . h
-}
  -- maybeh h (Predicate pᵇ) = Predicate (maybe False pᵇ . h)
  maybeh h (Predicate pᵇ) = h >$< Predicate (maybe False pᵇ)

@subttle
Copy link
Owner Author

subttle commented Dec 23, 2019

And if that works, why stop there? See if something like the following makes sense.

data List a = Nil | Cons a (List a)
class (Contravariant f) ⇒ ListH f where
  listh ∷ (a → List b) → f b → f a

But should probably consider both foldr and unfoldr destructors.
And then would need to consider how that might play out:

instance ListH Predicate where
  listh ∷ ∀ a b . (a → List b) → Predicate b → Predicate a
  listh h (Predicate pᵇ) = Predicate pᵃ
    where
      pᵃ ∷ Predicate a
      -- pᵃ = Predicate (\a → null (filter pᵇ (h a))) -- not (any pᵇ (h a))
      pᵃ = Predicate (null . filter pᵇ . h) -- not . any pᵇ . h
listh ∷ ∀ a b . (a → List b) → Equivalence b → Equivalence a

implying something like ∷ List b → List b → Bool so maybe equivalence of lists by length? So then I would imagine ∷ List b → List b → Ordering would then be comparing lists by length?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant