Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Prolog an untyped language? What's the difference between Prolog and dynamically typed languages?

If Prolog has clear distinction between strings, numbers, atoms, lists and compound structures how can it be called untyped. And how does it differ from dynamically typed languages like Lisp for example.

Which part of the definition of "dynamically typed language" does Prolog conflict with? And which part of the definition of "untyped language" does Lisp conflict with?

Any insight is appreciated.

Update

I already know what's the difference between dynamic, static, strong and weak typing. My question is about a special case which is Prolog. I just want to understand how is Prolog considered to be untyped though it doesn't seem to have a clear difference from dynamically typed languages.

Here's a reference that Prolog is untyped http://en.wikipedia.org/wiki/Prolog#Types

like image 223
is7s Avatar asked Jun 10 '11 18:06

is7s


2 Answers

Prolog is mostly untyped in the sense that you can pass any kind of term to any predicate and, usually, the worst case is that the predicate will not succeed. However, arithmetic predicates, such as is and =:= expect numeric arguments and may blow up - so there is a notion of types there.

Non-pure predicates might also expect objects of type "file handle" and blow up otherwise.

So, calling Prolog "untyped" is not strictly true.

like image 61
Nick Main Avatar answered Oct 30 '22 02:10

Nick Main


When you write a predicate like

head([H|_], H).

you don't specify any types anywhere. You can call head([1,2,3], X), you can call head("foo", X) and you can even call head(1, [1,2,3]). All of them run just fine. The last one won't cause any error, it will just return false.. I think that's what was meant by “untyped”.

like image 36
svick Avatar answered Oct 30 '22 02:10

svick