functional programming - Is it possible to get the infinite kind error in Haskell 98? -
i implementing kind system new functional programming language , writing function unify 2 kinds. there 4 cases 2 consider:
+---------+---------+-------------------------------------------------------+ | k1 | k2 | action | +=========+=========+=======================================================+ | var | var | k1 := k2 ^ k2 := k1 | +---------+---------+-------------------------------------------------------+ | var | non var | if (!occurs(k1, k2)) k1 := k2 | +---------+---------+-------------------------------------------------------+ | non var | var | if (!occurs(k2, k1)) k2 := k1 | +---------+---------+-------------------------------------------------------+ | non var | non var | ensure same name , arity, , unify respective args | +---------+---------+-------------------------------------------------------+
- when both
k1
,k2
variables instantiated each other. - when
k1
variable instantiatedk2
iffk1
doesn't occur ink2
. - when
k2
variable instantiatedk1
iffk2
doesn't occur ink1
. - otherwise check whether
k1
,k2
have same name , arity, , unify respective arguments.
for second , third cases need implement occurs check don't stuck in infinite loop. however, doubt programmer able construct infinite kind @ all.
in haskell, it's easy construct infinite type:
let f x = f
however, haven't been able construct infinite kind no matter how hard tried. note, didn't make use of language extensions.
the reason asking because if it's not possible construct infinite kind @ won't bother implementing occurs check kinds in kind system.
data f f = f (f f)
on ghc 7.10.1, message:
kind.hs:1:17: kind occurs check first argument of ‘f’ should have kind ‘k0’, ‘f’ has kind ‘(k0 -> k1) -> *’ in type ‘f f’ in definition of data constructor ‘f’ in data declaration ‘f’
the message doesn't it's infinite kind, that's when occurs check fails.
Comments
Post a Comment