Documents :: HomeBottomXHTML1 :: CSS2

Frequently Asked Questions

1. Introduction

We'll try here to answer few questions about Nemerle.

2. Why?

This section will answer questions about reasons behind Nemerle and choices made during development.

2.1. Platform

Q: Why use CLI/.NET?

A: Mainly interop reasons. There are number of CLI libraries and bindings out there already. There is going to be more and more. For example GNOME 4 is going to be written in C#.

Surely we'll loose WRT to compiled OCaml in terms of performance, at least until JIT's are made perfect, but it will be easily possible to write GNOME applet or Gimp plugin in Nemerle.

2.2. Comparing to C#...

Q: Why use Nemerle and not C#?

A: Nemerle is probably going to be used in some applications, where C# would be otherwise chosen. Why one would use Nemerle and not established, well described C#?

In Nemerle you can do mostly everything you would have done in C#. ,,mostly'' refers to unsafe code and maybe some C-interfacing tricks. But of course you can do more:

2.3. Dynamic types

Q: Why dynamic types? Doesn't they impact performance?

A: Probably yes. But dynamic types are inherent part of CLI so there is no performance reason to ban them (we would have to pay performance cost anyway). Additionally dynamic types are useful in some contexts, like dynamic loading of classes (or rather dynamic construction of objects).

For example what static type would you give to polymorphic de-serialization function? In OCaml it has type in_channel -> 'a which is obviously wrong.

Of course there are several religious issues about dynamic typing. Our answer is very simple: you don't need dynamic types -- don't use them.

2.4. Language extensions

Q: What language extensions are good for? Programmers are writing in languages not writing languages.

A: That's not true :-) Everyone programming X had an idea how to change this funny little annoying thing in X.

Of course not everybody is going to do it, but we're going to provide library of useful language extensions along with Nemerle. For example extension to generate various methods that can be automagically generated from structure of type, like:

It is also possible to define other function that we're unable to encode in our type-system. Ordinary example is C-like safe printf function.

We are also considering possibility of extending language syntax. However it is quite difficult to do this The Right Way.

3. Syntax questions

This section will try to answer few questions about Nemerle syntax, and sometimes semantics behind it.

3.1. Function call requires ()

Q: Why does function call require ()? f x looks much better then f(x), and in ML you can use both forms.

A: Function call requires (). It looks like this:

f (x, y, z);
f (x);
f ();

Form without () (i.e. f x) is not allowed.

There are some good reasons for that. The main one is that it allows for better overloading resolution (simply when looking at f (x, y) you know you need function with 2 parameters, and it's not partial application). Overloading is likely to occur quite frequently in CLI. Another is that following code will give you parse error, not weird typing error:

f (x)  (* forgot ';' here *)
g (x)

Using this syntax it is not possible to do partial application, but see below.

3.2. null value

Q: There is special 'a option type in ML, which can be Some x or None and is used where pointer that can be null would have been used in C-like languages. So what is null value good for? You can have option type in Nemerle too.

A: Of course you can, you even have it in standard library. It's suggested way of handling this matter.

But think about external functions that can return references. By CLI standards they can also return null. So it would require to have all functions returning foo in CLI to return option (foo) in Nemerle, and you would end up using val_of function over and over again, resulting in None_value (or something) exceptions instead of Null_pointer_exception.

This is why we have null in language. In fact it is quite common in Nemerle to have feature just for interop reasons.

3.3. Sequence in {}

Q: Why sequence needs to be enclosed in {}? Wouldn't it be possible to assign some priority to ; operator and treat this like expression?

A: It would be possible, but it's quite error-prone and misleading. In simple examples it's OK:

let x = 3 in g x; h x       (* Caml *)
{ def x = 3; g (x); h (x) }     (* Nemerle *)

But consider following snippet of Caml:

  (* Correct *)
  if x > y then
    let x = 3 in
    f x;
    g x
  else
    h ()

  (* Parse error *)
  if x > y then
    f 3;
    g 3
  else 
    h ()

Thanks to ; being used only in clear context it is not possible in Nemerle.

This issue is resolved in similar manner in OCaml Revised Syntax.

3.4. if requires else

Q: Why does if require else? In OCaml one doesn't need to write else ().

A: To avoid confusing grammar ambiguities. Beside this is functional language, what is if expression without else?

You can also use when and unless macros for if without else or else without if.

4. Where did X go?

Few explanations about how to do various things in Nemerle.

4.1. Partial application

Q: Where is partial function application?

A: You simply need to use so called eta-long form:

def f (x, y) { ... };
def g (x) { fun (y) { f (x, y) } };

def plus5 (x) { fun (x) { 5 + x } };

This prevents partial application bugs, which would be common in presence of overloading.


Documents :: HomeTopXHTML1 :: CSS2