Skip to content

Instantly share code, notes, and snippets.

@haskie-lambda
Created May 31, 2021 16:02
Show Gist options
  • Save haskie-lambda/b095c6a687eb07d964221129eba14546 to your computer and use it in GitHub Desktop.
Save haskie-lambda/b095c6a687eb07d964221129eba14546 to your computer and use it in GitHub Desktop.
Prelude> :set -XGADTs
Prelude> :set -XEmptyDataDecls
Prelude> :{
Prelude| data List l a where
Prelude| Nil :: List Empty a
Prelude| (:-) :: a -> List l a -> List NE a
Prelude| :}
Prelude>
Prelude> :set -XStandaloneDeriving
Prelude> deriving instance (Show a) => Show (List l a)
Prelude> (12::Int) :- ((13::Int) :- Nil)
(:-) 12 ((:-) 13 Nil)
Prelude> import Unsafe.Coerce
Prelude Unsafe.Coerce> let indexedAs = (12::Int) :- ((13::Int) :- Nil)
Prelude Unsafe.Coerce> unsafeCoerce indexedAs :: [Int]
[12,13]
Prelude Unsafe.Coerce> let indexedAs = (Nil :: List Empty Int)
Prelude Unsafe.Coerce> unsafeCoerce indexedAs :: [Int]
[]
Prelude Unsafe.Coerce> let indexedErrs = (12::Int) :- ((undefined::Int) :- Nil)
Prelude Unsafe.Coerce> unsafeCoerce indexedAs :: [Int]
Prelude Unsafe.Coerce> head $ (unsafeCoerce indexedErrs :: [Int])
12
Prelude Unsafe.Coerce>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment