Are there any static duck-typed languages?

前端 未结 15 1055
我寻月下人不归
我寻月下人不归 2020-12-14 10:12

Can I specify interfaces when I declare a member?

After thinking about this question for a while, it occurred to me that a static-duck-typed language might actually

15条回答
  •  甜味超标
    2020-12-14 10:35

    Crystal is a statically duck-typed language. Example:

    def add(x, y)
      x + y
    end
    
    add(true, false)
    

    The call to add causes this compilation error:

    Error in foo.cr:6: instantiating 'add(Bool, Bool)'
    
    add(true, false)
    ^~~
    
    in foo.cr:2: undefined method '+' for Bool
    
      x + y
        ^
    

提交回复
热议问题