Skip to content

Instantly share code, notes, and snippets.

@friedbrice
Last active August 8, 2020 03:51
Show Gist options
  • Save friedbrice/583b1108095c97511fe54a9aa9a64a1c to your computer and use it in GitHub Desktop.
Save friedbrice/583b1108095c97511fe54a9aa9a64a1c to your computer and use it in GitHub Desktop.
{-# LANGUAGE DataKinds, KindSignatures, GADTs, TypeOperators #-}
module BlockMatrix where
import GHC.TypeLits
data Block (n :: Nat) (m :: Nat) a where
Number :: a -> Block 1 1 a
Fourths :: Block n1 m1 a -> Block n1 m2 a -> Block n2 m1 a -> Block n2 m2 a -> Block (n1 + n2) (m1 + m2) a
Vhalves :: Block n m1 a -> Block n m2 a -> Block n (m1 + m2) a
Hhalves :: Block n1 m a -> Block n2 m a -> Block (n1 + n2) m a
i4 :: Block 2 2 Double
i4 = Hhalves col1 col2
where
col1 :: Block 1 2 Double
col1 = Vhalves x11 x21
where
x11 :: Block 1 1 Double
x11 = Number 1
x21 :: Block 1 1 Double
x21 = Number 0
col2 :: Block 1 2 Double
col2 = Vhalves x12 x22
where
x12 :: Block 1 1 Double
x12 = Number 0
x22 :: Block 1 1 Double
x22 = Number 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment