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

Move ccase_SList into All class #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions sop-core/src/Data/SOP/Constraint.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,33 @@ class (AllF c xs, SListI xs) => All (c :: k -> Constraint) (xs :: [k]) where
-> (forall y ys . (c y, All c ys) => r ys -> r (y ': ys))
-> r xs

-- | Constrained case distinction on a type-level list.
--
-- @since 0.4.0.0
--
ccase_SList ::
All c xs
=> proxy c
-> ((xs ~ '[]) => r '[])
-> (forall y ys . (c y, All c ys, (y ': ys) ~ xs) => r (y ': ys))
-> r xs

instance All c '[] where
cpara_SList _p nil _cons = nil
{-# INLINE cpara_SList #-}

ccase_SList _p nil _cons =
nil
{-# INLINE ccase_SList #-}

instance (c x, All c xs) => All c (x ': xs) where
cpara_SList p nil cons =
cons (cpara_SList p nil cons)
{-# INLINE cpara_SList #-}

-- | Constrained case distinction on a type-level list.
--
-- @since 0.4.0.0
--
ccase_SList ::
All c xs
=> proxy c
-> r '[]
-> (forall y ys . (c y, All c ys) => r (y ': ys))
-> r xs
ccase_SList p nil cons =
cpara_SList p nil (const cons)
{-# INLINE ccase_SList #-}
ccase_SList _p _nil cons =
cons
{-# INLINE ccase_SList #-}

-- | Type family used to implement 'All'.
--
Expand Down