Skip to content

WIP: DecideEq #35

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions dec/src/Data/Type/Dec.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeOperators #-}
module Data.Type.Dec (
-- * Types
Neg,
Dec (..),
Decidable (..),
DecideEq (..),
-- * Neg combinators
toNegNeg,
tripleNeg,
Expand All @@ -15,6 +19,7 @@ module Data.Type.Dec (
decToBool,
) where

import Data.Type.Equality ((:~:) (..))
import Data.Void (Void)

-- | Intuitionistic negation.
Expand All @@ -36,6 +41,15 @@ data Dec a
class Decidable a where
decide :: Dec a

-- | Decidable equality.
--
-- @since 0.0.4
class DecideEq s where
decideEq :: s a -> s b -> Dec (a :~: b)

instance DecideEq ((:~:) c) where
decideEq Refl Refl = Yes Refl

-------------------------------------------------------------------------------
-- Neg combinators
-------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion fin/src/Data/Fin.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE EmptyCase #-}
-- | Finite numbers.
--
-- This module is designed to be imported as
Expand Down
9 changes: 9 additions & 0 deletions fin/src/Data/Type/Nat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ discreteNat = getDiscreteNat $ induction (DiscreteNat start) (\p -> DiscreteNat

newtype DiscreteNat n = DiscreteNat { getDiscreteNat :: forall m. SNatI m => Dec (n :~: m) }

-- |
--
-- @since 0.1.1
instance DecideEq SNat where
decideEq SZ SZ = Yes Refl
decideEq SS SS = discreteNat
decideEq SS SZ = No $ \p -> case p of {}
decideEq SZ SS = No $ \p -> case p of {}

instance TestEquality SNat where
testEquality SZ SZ = Just Refl
testEquality SZ SS = Nothing
Expand Down