10
votes

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

2
do you have a reference for this?Vincent Ramdhanie
I thing you are mixing up strong typing and dynamic typing.mikerobi
a reference for what exactly ?is7s
A reference for someone calling Prolog an "untyped language" would be helpful. The opposite of dynamic typing is not "untyped" but static typing, i.e. types for variables determined at compilation.hardmath

2 Answers

5
votes

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.

1
votes

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”.