我正在尝试编写代码以从元组链中删除空元组。编译器拒绝该程序:
代码:
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeOperators #-}
infixr 9 :*
data a :* b = a :* !b
deriving (Show, Eq, Ord)
class Flatten a b | a -> b where
flatten :: a -> b
instance Flatten a a where
flatten = id
instance Flatten a b => Flatten (() :* a) b where
flatten (() :* y) = flatten y
instance Flatten b c => Flatten (a :* b) (a :* c) where
flatten (x :* y) = x :* flatten y
test :: Int :* ()
test = flatten $ 0 :* ()
[1 of 1] Compiling Main ( Test\Test.hs, interpreted )
Test\Test.hs:26:8:
Overlapping instances for Flatten (Int :* ()) (Int :* ())
arising from a use of `flatten'
Matching instances:
instance [overlap ok] Flatten a a
-- Defined at Test\Test.hs:15:10-20
instance [overlap ok] Flatten b c => Flatten (a :* b) (a :* c)
-- Defined at Test\Test.hs:21:10-49
In the expression: flatten
In the expression: flatten $ 0 :* ()
In an equation for `test': test = flatten $ 0 :* ()
Failed, modules loaded: none.
目标:
flatten (0:*():*1:*2:3:*():*():*4:*()) == (0:*1:*2:*3:*4:*())