-
Notifications
You must be signed in to change notification settings - Fork 380
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
refactor Uninhabited implementation for Elem types #3412
base: main
Are you sure you want to change the base?
Changes from 1 commit
872fde9
1c82b4b
d33446b
ca39508
2aacf3c
5a8009a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,11 @@ data Elem : a -> List a -> Type where | |
There : Elem x xs -> Elem x (y :: xs) | ||
|
||
export | ||
Uninhabited (Here = There e) where | ||
Uninhabited (Here {x} {xs} = There {x = x'} {y} {xs} e) where | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're going fully heterogeneous, why not have two different There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think this can be proven for any |
||
uninhabited Refl impossible | ||
|
||
export | ||
Uninhabited (There e = Here) where | ||
Uninhabited (There {x} {y} {xs} e = Here {x = x'} {xs}) where | ||
uninhabited Refl impossible | ||
|
||
export | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Data.List | ||
import Data.List.Elem | ||
|
||
decHomogeneousElem : (el1 : Elem x xs) -> (el2 : Elem x xs) -> Dec (el1 = el2) | ||
decHomogeneousElem Here Here = Yes Refl | ||
decHomogeneousElem (There _) Here = No uninhabited | ||
decHomogeneousElem Here (There _) = No uninhabited | ||
decHomogeneousElem (There el1') (There el2') = case decHomogeneousElem el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
decHeterogeneousElem : (el1 : Elem x xs) -> (el2 : Elem y xs) -> Dec (el1 = el2) | ||
decHeterogeneousElem Here Here = Yes Refl | ||
decHeterogeneousElem (There _) Here = No uninhabited | ||
decHeterogeneousElem Here (There _) = No uninhabited | ||
decHeterogeneousElem (There el1') (There el2') = case decHeterogeneousElem el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
main : IO () | ||
main = printLn "OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
run Elem.idr |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Data.List | ||
import Data.List.Elem | ||
import Data.List1 | ||
import Data.List1.Elem | ||
|
||
decHomogeneousElemList : (el1 : Data.List.Elem.Elem x xs) -> (el2 : Data.List.Elem.Elem x xs) -> Dec (el1 = el2) | ||
decHomogeneousElemList Here Here = Yes Refl | ||
decHomogeneousElemList (There _) Here = No uninhabited | ||
decHomogeneousElemList Here (There _) = No uninhabited | ||
decHomogeneousElemList (There el1') (There el2') = case decHomogeneousElemList el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
decHeterogeneousElemList : (el1 : Data.List.Elem.Elem x xs) -> (el2 : Data.List.Elem.Elem y xs) -> Dec (el1 = el2) | ||
decHeterogeneousElemList Here Here = Yes Refl | ||
decHeterogeneousElemList (There _) Here = No uninhabited | ||
decHeterogeneousElemList Here (There _) = No uninhabited | ||
decHeterogeneousElemList (There el1') (There el2') = case decHeterogeneousElemList el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
decHomogeneousElem : (el1 : Data.List1.Elem.Elem x xs) -> (el2 : Data.List1.Elem.Elem x xs) -> Dec (el1 = el2) | ||
decHomogeneousElem Here Here = Yes Refl | ||
decHomogeneousElem (There _) Here = No uninhabited | ||
decHomogeneousElem Here (There _) = No uninhabited | ||
decHomogeneousElem (There el1') (There el2') = case decHomogeneousElemList el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
decHeterogeneousElem : (el1 : Data.List1.Elem.Elem x xs) -> (el2 : Data.List1.Elem.Elem y xs) -> Dec (el1 = el2) | ||
decHeterogeneousElem Here Here = Yes Refl | ||
decHeterogeneousElem (There _) Here = No uninhabited | ||
decHeterogeneousElem Here (There _) = No uninhabited | ||
decHeterogeneousElem (There el1') (There el2') = case decHeterogeneousElemList el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
main : IO () | ||
main = printLn "OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
run Elem.idr |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Data.SnocList | ||
import Data.SnocList.Elem | ||
|
||
decHomogeneousElem : (el1 : Elem x xs) -> (el2 : Elem x xs) -> Dec (el1 = el2) | ||
decHomogeneousElem Here Here = Yes Refl | ||
decHomogeneousElem (There _) Here = No uninhabited | ||
decHomogeneousElem Here (There _) = No uninhabited | ||
decHomogeneousElem (There el1') (There el2') = case decHomogeneousElem el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
decHeterogeneousElem : (el1 : Elem x xs) -> (el2 : Elem y xs) -> Dec (el1 = el2) | ||
decHeterogeneousElem Here Here = Yes Refl | ||
decHeterogeneousElem (There _) Here = No uninhabited | ||
decHeterogeneousElem Here (There _) = No uninhabited | ||
decHeterogeneousElem (There el1') (There el2') = case decHeterogeneousElem el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
main : IO () | ||
main = printLn "OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
run Elem.idr |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Data.Vect | ||
import Data.Vect.Elem | ||
|
||
decHomogeneousElem : (el1 : Elem x xs) -> (el2 : Elem x xs) -> Dec (el1 = el2) | ||
decHomogeneousElem Here Here = Yes Refl | ||
decHomogeneousElem (There _) Here = No uninhabited | ||
decHomogeneousElem Here (There _) = No uninhabited | ||
decHomogeneousElem (There el1') (There el2') = case decHomogeneousElem el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
decHeterogeneousElem : (el1 : Elem x xs) -> (el2 : Elem y xs) -> Dec (el1 = el2) | ||
decHeterogeneousElem Here Here = Yes Refl | ||
decHeterogeneousElem (There _) Here = No uninhabited | ||
decHeterogeneousElem Here (There _) = No uninhabited | ||
decHeterogeneousElem (There el1') (There el2') = case decHeterogeneousElem el1' el2' of | ||
Yes Refl => Yes Refl | ||
No contra => No $ \Refl => contra Refl | ||
|
||
main : IO () | ||
main = printLn "OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"OK" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../testutils.sh | ||
|
||
run Elem.idr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a brief sentence explaining why / explaining what the refactor achieves?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done