, (1) , (2) ; (type ExampleOfATypeSynonym = ...) , , , , :
-- (1)
class Foo a
type Bla = ()
instance Foo Bla
... :
-- (2)
class Foo a
type Bla = ()
instance (a ~ Bla) => Foo a
, (1) , , , : , type B = A instance Foo B, , Foo A. , instance Foo A , , , .
, , , NameRecord. , FieldOf Name, ; , " " , FieldOf Name " " Name :> Text . , "" .
GHC.
, "... (2) , (1) ..."
, :
class Foo a where
foo :: a
:
instance Foo Int where
foo = 0
instance Foo Float where
foo = 0
main :: IO ()
main = print (foo :: Float)
, . , :
{-# LANGUAGE FlexibleInstances, TypeFamilies #-}
class Foo a where
foo :: a
instance (a ~ Int) => Foo a where
foo = 0
instance (a ~ Float) => Foo a where
foo = 0
main :: IO ()
main = print (foo :: Float)
; :
test.hs:5:10:
Duplicate instance declarations:
instance a ~ Int => Foo a -- Defined at test.hs:5:10-27
instance a ~ Float => Foo a -- Defined at test.hs:8:10-29
, , . , Foo, . ?
GHC , ; .. =>. , "" =>, , . , :
instance Foo a where ...
instance Foo a where ...
, , .