Defining restricted subset of Storable for type match

1
2
3
4
5
6
7
8
9
10
11
12
{-#  LANGUAGE BangPatterns, GADTs #-}
import Data.Vector.Storable as SV
import Foreign.C.Types (CChar)
import GHC.Int (Int32)

data AList a where
  I :: {-# UNPACK #-} !(SV.Vector Int32) -> AList (SV.Vector Int32)
  S :: {-# UNPACK #-} !(SV.Vector CChar) -> AList (SV.Vector CChar)

dispatch :: (Storable a) => AList (SV.Vector a) -> SV.Vector a
dispatch (I x) = x
dispatch (S x) = x