Created
August 12, 2019 20:54
-
-
Save MarcelineVQ/f6f6ab1a32fa5db5225d5a92bb4c61f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Ferdirand> i'm trying to define a type for lists of two alternating types | |
| <Ferdirand> data Chain a b l where | |
| <Ferdirand> Nil :: Chain a b b | |
| <Ferdirand> (:@) :: a -> Chain b a l -> Chain a b l | |
| <Ferdirand> l represents the statically-known type of the last element | |
| <Ferdirand> now, for the type Chain (a b a), which has the same type for the first and last element, i know that if a and b are different types, then the list cannot be empty | |
| <Ferdirand> and i'd like to write a type-safe `last` function that reflects that | |
| <Ferdirand> data Chain a b l where | |
| <Ferdirand> Nil :: Chain a b b | |
| <Ferdirand> (:@) :: a -> Chain b a l -> Chain a b l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment