Skip to content

Instantly share code, notes, and snippets.

@msmorgan
Created November 10, 2017 05:48
Show Gist options
  • Save msmorgan/bd191cb971fa6a2ef38c66eaedcf6a67 to your computer and use it in GitHub Desktop.
Save msmorgan/bd191cb971fa6a2ef38c66eaedcf6a67 to your computer and use it in GitHub Desktop.
module Data.AltList
%access public export
%default total
data AltList : (a : Type) -> (b : Type) -> Type where
Nil : AltList a b
ConsB : b -> AltList a b -> AltList a b
ConsAB : a -> b -> AltList a b -> AltList a b
data IsConsB : AltList a b -> Type where
ItIsConsB : IsConsB (ConsB x xs)
namespace ConsB
(::) : b -> AltList a b -> AltList a b
(::) = ConsB
namespace ConsA
(::) : a -> (xs : AltList a b) -> {auto ok : IsConsB xs} -> AltList a b
(::) x (ConsB y xs) = ConsAB x y xs
stringIntList : AltList String Int
stringIntList = ["hello", 1, "world", 2]
@Melvar
Copy link

Melvar commented Nov 10, 2017

This allows any number of bs in sequence, rather than requiring them to alternate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment