static-typing

Cannot create apply function with static language?

左心房为你撑大大i 提交于 2019-12-03 09:27:57
问题 I have read that with a statically typed language like Scala or Haskell there is no way to create or provide a Lisp apply function: (apply #'+ (list 1 2 3)) => 6 or maybe (apply #'list '(list :foo 1 2 "bar")) => (:FOO 1 2 "bar") (apply #'nth (list 1 '(1 2 3))) => 2 Is this a truth? 回答1: A full APPLY is difficult in a static language. In Lisp APPLY applies a function to a list of arguments. Both the function and the list of arguments are arguments to APPLY. APPLY can use any function. That

Applying Extension method to generic class with generic type

余生颓废 提交于 2019-12-03 06:12:30
I was working with the generic class in vb.net. And it seems extension method cannot be applied to generic class without specifying the type. I have this generic class Public Class MyGeneric(Of T) 'Methods and properties go here ' ' End Class This is Ok <Extension()> _ Public Sub DoSomething(ByVal myGenericDoubleObj As MyGen(Of Double)) End Sub This is NOT Ok(IDE gives me error T as not defined.) <Extension()> _ Public Sub DoSomethingGeneric(ByVal myGenericObj As MyGen(Of T)) End Sub Is this something to do with the static checking of the .Net. Saying me "Something which may you try with doing

Do you know of a language with Static Type checking where Code is Data? [closed]

*爱你&永不变心* 提交于 2019-12-03 05:57:45
Can you name languages with static type checking (like Java) and where code is data (like in LISP)? I mean both things in one language. Qi is a statically-typed Lisp dialect. Also, many other Lisp dialects have (optional) static typing. Java itself has very limited capabilities of this kind. The interesting question is not so much whether you can have metaprogramming and static typing, it's whether you can have dynamic metaprogramming be statically type-safe . There is Template Haskell which does metaprogramming and is type-safe, but it is static metaprogramming. At the moment I can not think

Statically typed Lua

南笙酒味 提交于 2019-12-03 05:54:46
问题 I am looking for a Lua front-end compiler that is type-checked at compile time, but outputs standard Lua 5.1 byte-code (that has only run-time types). What I want is a decent amount of static, compile-time syntactic analysis and optional typing, to detect trivial errors sooner than run-time. The resulting byte-code would have to play nicely with existing Lua byte-code that was compiled with the standard LoadString(). To be clear -- any difference would only occur at byte-compilation time. At

Is it possible to specify an anonymous function's return type, in Scala?

风格不统一 提交于 2019-12-03 04:16:54
问题 I know you can create an anonymous function, and have the compiler infer its return type: val x = () => { System.currentTimeMillis } Just for static typing's sake, is it possible to specify its return type as well? I think it would make things a lot clearer. 回答1: In my opinion if you're trying to make things more clear it is better to document the expectation on the identifier x by adding a type annotation there rather than the result of the function. val x: () => Long = () => System

Is there a compiled* programming language with dynamic, maybe even weak typing?

青春壹個敷衍的年華 提交于 2019-12-03 04:15:19
I wondered if there is a programming language which compiles to machine code/binary (not bytecode then executed by a VM, that's something completely different when considering typing) that features dynamic and/or weak typing, e.g: Think of a compiled language where: Variables don't need to be declared Variables can be created during runtime Functions can return values of different types Questions: Is there such a programming language? (Why) not? I think that a dynamically yet strong typed, compiled language would really sense, but is it possible? I believe Lisp fits that description. http://en

Statically typed Lua

梦想的初衷 提交于 2019-12-02 19:16:27
I am looking for a Lua front-end compiler that is type-checked at compile time, but outputs standard Lua 5.1 byte-code (that has only run-time types). What I want is a decent amount of static, compile-time syntactic analysis and optional typing, to detect trivial errors sooner than run-time. The resulting byte-code would have to play nicely with existing Lua byte-code that was compiled with the standard LoadString(). To be clear -- any difference would only occur at byte-compilation time. At runtime, the byte code would have no idea that anything different/unusual happened to it during the

Is it possible to specify an anonymous function's return type, in Scala?

北战南征 提交于 2019-12-02 17:34:50
I know you can create an anonymous function, and have the compiler infer its return type: val x = () => { System.currentTimeMillis } Just for static typing's sake, is it possible to specify its return type as well? I think it would make things a lot clearer. In my opinion if you're trying to make things more clear it is better to document the expectation on the identifier x by adding a type annotation there rather than the result of the function. val x: () => Long = () => System.currentTimeMillis Then the compiler will ensure that the function on the right hand side meets that expectation. val

TypeScript: problems with type system

血红的双手。 提交于 2019-12-02 16:02:59
I'm just testing typescript in VisualStudio 2012 and have a problem with its type system. My html site has a canvas tag with the id "mycanvas". I'm trying to draw a rectangle on this canvas. Here's the code var canvas = document.getElementById("mycanvas"); var ctx: CanvasRenderingContext2D = canvas.getContext("2d"); ctx.fillStyle = "#00FF00"; ctx.fillRect(0, 0, 100, 100); Unfortunately VisualStudio complains that the property 'getContext' does no exist on value of type 'HTMLElement' It marks the second line as an error. I thought this would be merely a warning but the code does not compile.

How can I ensure that the dynamic type of my custom Scala collection is preserved during a map()?

为君一笑 提交于 2019-12-01 21:49:33
问题 I read the very interesting article on the architecture of the Scala 2.8 collections and I've been experimenting with it a little bit. For a start, I simply copied the final code for the nice RNA example. Here it is for reference: abstract class Base case object A extends Base case object T extends Base case object G extends Base case object U extends Base object Base { val fromInt: Int => Base = Array(A, T, G, U) val toInt: Base => Int = Map(A -> 0, T -> 1, G -> 2, U -> 3) } final class RNA