Crystal

Ary Borenszweig ary at esperanto.org.ar
Sun Feb 17 08:11:47 PST 2013


On 2/17/13 6:29 AM, Denis Shelomovskij wrote:
 > I'd like to specify function attributes explicitly because I do want to
 > get a compilation error when I e.g. use non-safe stuff in safe function
 > instead of a just compiler silently changing the function (and all
 > functions which use it) to unsafe.=

It's something I didn't have time to write in that wiki page, but you 
can restrict the types of a function.

def foo(x : Int)
   1
end

foo "Hello" # Gives a compile-time error

This is similar to what you can do with D templates. You can also 
restrict an overload an use another one unrestricted and it will choose 
the correct one:

def foo(x : Int)
   1
end

def foo(x)
   2
end

foo "Hello" # Chooses the second one

So theoretically you can type everything you want. We might also support 
typing a variable in order to disallow it to change to another type (I 
think this is what is done in the Julia language).

 >
 > Now about argument types. I do not understand the purpose of dynamic
 > typing at all and consider such languages too dangerous to use in real
 > projects.

In the place I work we've written several web applications and programs 
in Ruby and they work just fine. We writes lots of test units to make 
sure everything works (you don't have another option, really, with 
dynamic languages).

 > Sorry for such cruel comment, I it is just my opinion.

It's not cruel at all. I really appreciate your comments.




More information about the Digitalmars-d-announce mailing list