長さ固定リスト

長さをタイプチェックできるリストが欲しかったので、

infixr 5 :*:
data FixedList b a = a :*: b a -- deriving Show
-- 要るかな?
data Nul a = Nul deriving (Show, Eq)

instance Functor Nul where
  fmap _ _ = Nul
instance Functor b => Functor (FixedList b) where
  fmap f (a :*: b) = f a:*:fmap f b

というものを作ってみた。

fmap show $ (1 :*: 2 :*: Null)
fmap (+ 1) $ (1 :*: 2 :*: [])

などとできる。でも、どうやれば

class HomSeq ... where
  shead :: ...
  stail :: ...
  scons :: ...
  snull :: ...
  sempty :: ...
instance HomSeq [] ... where
instance (...) => HomSeq (FixedList b) ... where

とできるかが分からない。semptyで詰まる…Hugsでも動くようにFunDep*1でできないだろうか。

追記

問題は別の所にあったのを発見。

*1:Functional Dependency