I'm having trouble with unsaturated type synonyms in the following example:
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE LiberalTypeSynonyms #-}
module TypeFamilyHackery where
data T k v a = T
type family CollectArgTypes arr where
CollectArgTypes (a -> b) = (a, CollectArgTypes b)
CollectArgTypes _ = ()
type family MapReturnType f t where
MapReturnType f (a -> b) = a -> MapReturnType f b
MapReturnType f r = f r
type MkT k v = T k v v
-- | Goal:
-- @
-- BuryT Int = T () Int Int
-- BuryT (Bool -> Int) = Bool -> T (Bool, ()) Int Int
-- BuryT (a -> b -> c) = a -> b -> T (a,(b,())) c c
-- @
type BuryT t = MapReturnType (MkT (CollectArgTypes t)) t
But this complains with The type synonym 'MkT' should have 2 arguments, but has been given 1
. I could specialize MapReturnType
for MkT (CollectArgTypes t)
, but I rather like it how it is.
Since -XLiberalTypeSynonyms
doesn't seem to deliver (why?), what are my options to get BuryT
working?