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 | +---------+---------+-------------------------------------------------------+ 
  1. when both k1 , k2 variables instantiated each other.
  2. when k1 variable instantiated k2 iff k1 doesn't occur in k2.
  3. when k2 variable instantiated k1 iff k2 doesn't occur in k1.
  4. 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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -