Skip to content

Instantly share code, notes, and snippets.

@oliver-batchelor
Last active October 1, 2016 02:42
Show Gist options
  • Save oliver-batchelor/247118bc6f15badbcf05b3abc94830f9 to your computer and use it in GitHub Desktop.
Save oliver-batchelor/247118bc6f15badbcf05b3abc94830f9 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TemplateHaskell, FlexibleContexts, FlexibleInstances, GADTs, DataKinds,
TypeInType, KindSignatures, InstanceSigs, TypeOperators,
ConstraintKinds, RankNTypes, ScopedTypeVariables, TypeFamilies,
UndecidableInstances, MultiParamTypeClasses, TypeApplications, PartialTypeSignatures #-}
$(singletons [d|
data UNat = Zero | Succ UNat
deriving (Eq)
|])
class Concats (d:: UNat) (xs::[Nat]) (ys::[Nat]) where
type ConcatShape d xs ys :: [Nat]
instance (xs ~ ys) => Concats 'Zero (x:xs) (y:ys) where
type ConcatShape Zero (x:xs) (y:_) = (x + y : xs)
instance (x ~ y) => Concats ('Succ n) (x:xs) (y:ys) where
type ConcatShape (Succ n) (x:xs) (_:ys) = x : ConcatShape n xs ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment