# import sets
    import strformat
    
    {.experimental:"callOperator".}
    
    type
        Object = ref object of RootObj
            name : string
        
        Morphism = ref object of Object
            domain : ref Object
            codomain : ref Object
    
    method `()`(g:ref Morphism, f:ref Morphism):Morphism {.base.} =
        let h = new Morphism
        h.domain = f.domain
        h.codomain = g.codomain
        h.name = fmt"{g.name}⚬{f.name}"
        return h
    
    let X = Object(name:"X")
    let Y = Object(name:"Y")
    let Z = Object(name:"Z")
    var f = Morphism(domain:X, codomain:Y)
    var g = Morphism(domain:Y, codomain:Z)
    var h = g(f)
    echo h.name
    
    
    Run

Errors:
    hello.nim(47, 24) Error: type mismatch: got 'Object' for 'X' but expected 
'ref Object'

I've tried about 20 other permutations of code. It's really dumb that we have 
no easy way to create objects. What is the point of all this complexity? Please 
keep the language design simple. 

Reply via email to