[Haskell-cafe] Learn Prolog...

Andrew Coppin andrewcoppin at btinternet.com
Sun Sep 2 09:59:27 EDT 2007

jerzy.karczmarczuk at info.unicaen.fr wrote:
> Andrew Coppin writes:
>> Ever tried implementing Haskell in Haskell? ;-)
> Seriously:
> Haskell is a *complicated* language, needing a parser, which by itself is
> a non-trivial exercice.

It looks so simple on the surface...

[Actually, so does cold fusion.]

>> Read my whole message. What I was saying (in essence) is that Prolog 
>> seemed to be performing "impossible" feats of logical deduction - 
>> until I saw a unification algorithm implemented in Haskell, and then 
>> it all made sense.
> My deepest congratulations. It seems that you are the first person in my
> pedagogical life, who got acquainted with the unification through its
> implementation in Haskell.

Heh. Well. It took a *long* time, mind you... (BTW, that's a really 
rather good book, that.)

>> Having said all that, I still don't "get" what the purpose of the 
>> "cut" operator is. 
> Imagine that your life is a path through a tree. Depth first. At every
> branching you choose a branch, and you continue. When you are stuck, you
> remember that you have left a trail behind you, and you backtrack until
> the last choice point. Then you choose another path, the previous being
> marked as 'seen'.
> Well, the cut is a commitment. You cut your way back, Now, you must 
> succeed,
> i.e., find a terminal node which gives you what you want, or your failure
> is definitive, you jump out of the system. There are hundreds of easy
> examples of cuts, e.g., when descending the tree consumes the ressources
> which cannot be restored.

So... it's the opposite of Parsec's "try" combinator?

>> I also failed to understand the Prolog syntax description. (What the 
>> heck is an "atom" when it's at home? I thought an atom is a unit 
>> composed of protons and electrons...)
> Now, you are pulling my leg. An "atom" means that you cannot split it in
> constituents, this name came from Lisp into other languages, but the 
> meaning comes from Democritus, who didn't know protons. I won't say 
> more, just that
> if you want to be really funny, you should not forget neutrons.

Well, true. But they're so neutral! They don't even affect the chemical 
properties of the atom, only its physical ones. ;-)

[Actually, I'm told this isn't *quite* true. For example, heavy water is 
mildly toxic due to the atom radius being slightly different or 
something which means that some enzyme somewhere doesn't quite work 
properly any more, or similar...]

But anyway, I usually find that language syntax descriptions are written 
for maximum crypticness... This is presumably to enhance the idea that 
only extremely intelligent people can understand it or something.

>> I can certainly see why Prolog would be very useful for certain types 
>> of problems. As it happens, not the kind of problems that usually 
>> interest me. ;-)
> Well, who am I or other readers to contradict it?...
> My point was that learning more than one language

Do you have Any Idea how many programming languages I've learned and 
used in my life so far? (Hint: lots.) ;-)

[Hell, I was bored one day so I learned PostScript in my lunch break... 
Most normal people don't do that.]

More information about the Haskell-Cafe mailing list