Preventing CAT calls in Generics

Revision as of 17:22, 5 March 2007 by Juliant (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Warning.png Warning: Warning: Article under development

Introduction

Example

class T 
end
 
class U 
inherit T 
  -- no covariant feature redefinition
end

Conformance

Type conformance

conforms to T T..NONE ANY..T U
T true false true false
T..NONE true false true false
ANY..T false false false false
U true false true true

Generic conformance

conforms to LIST [ANY] LIST [T] LIST [T..NONE] LIST [ANY..T] LIST [U]
LIST [ANY] true false false true false
LIST [T] false true true true false
LIST [T..NONE] false false true false false
LIST [ANY..T] false false false true false
LIST [U] false false true false true
-- legal
T := LIST [T..NONE] .item
LIST [T..NONE] .put (Void)
 
  -- illegal
U := LIST [T..NONE] .item
LIST [T..NONE] .put (T)
 
  -- legal
LIST [ANY..T] .put (T)
LIST [ANY..T] .put (U)
ANY := LIST [ANY..T] .item
 
  -- illegal
LIST [ANY..T] .put (ANY)
T := LIST [ANY..T] .item

Agents

Procedure class:

class PROCEDURE [BASE_TYPE, OPEN_ARGS -> TUPLE []]
 
  call (args: OPEN_ARGS)
    do end
 
end

agent (T)

Type declaration:

an_agent: PROCEDURE [ANY..NONE, TUPLE..TUPLE [ANY..T]]  --> like agent (T)
  -- signature for call has to be inverted: TUPLE [T..NONE]..NONE
 
  -- legal
an_agent.call ([T])
an_agent.call ([T, ...])
an_agent.call ([U, ...])
 
  -- illegal
an_agent.call ([])

Instantiation:

agent_empty := agent () do end --> PROCEDURE [ANY, TUPLE []]
agent_any := agent (a: ANY) do end --> PROCEDURE [ANY, TUPLE [ANY]]
agent_t := agent (t: T) do end --> PROCEDURE [ANY, TUPLE [T]]
agent_u := agent (u: U) do end --> PROCEDURE [ANY, TUPLE [U]]
 
  -- legal
an_agent := agent_empty
an_agent := agent_any
an_agent := agent_t
 
  -- illegal
an_agent := agent_u