Skip to content

Instantly share code, notes, and snippets.

@jmitchell
Created September 16, 2017 21:16
Show Gist options
  • Save jmitchell/fc911e7cdce12109de7919a88abbff13 to your computer and use it in GitHub Desktop.
Save jmitchell/fc911e7cdce12109de7919a88abbff13 to your computer and use it in GitHub Desktop.
Key-value mapping in Idris where set of keys that have values is encoded in the type
import Data.List
data SetMap : List k -> Type -> Type where
Empty : SetMap [] _
Insert : DecEq k =>
(key : k) ->
v ->
SetMap keys v ->
{auto prf : isElem key keys = No _} ->
SetMap (key :: keys) v
example : SetMap ["a", "b"] Nat
example = Insert "a" 2 $
Insert "b" 1 $
Empty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment