I have troubles implementing IsList
instance for GADT
which represents structure of values inside nested arrays. Here is complete code:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
import GHC.Exts (IsList (..))
data ValType = TInt | TList
data Val (t :: ValType) where
I :: Int -> Val 'TInt
L :: [Val a] -> Val 'TList
instance Show (Val t) where
show (I i) = "I " ++ show i
show (L a) = show a
instance IsList (Val 'TList) where
type Item (Val 'TList) = forall a . Val a
fromList = L
toList = error "Not implemented!"
I see such error:
GADT.hs:20:10: error:
• Illegal polymorphic type: forall (a :: ValType). Val a
• In the type instance declaration for ‘Item’
In the instance declaration for ‘IsList (Val 'TList)’
|
20 | type Item (Val 'TList) = forall a . Val a
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I partially understand why I have this error. But I would like know if it's possible to implement IsList
instance for Val
type?