[Haskell-cafe] Bool is not...safe?!
PY
aquagnu at gmail.com
Mon Jul 9 10:08:34 UTC 2018
09.07.2018 11:50, Dušan Kolář wrote:
>
> Hmm, but CLP has completely different way of evaluation and program
> construction than Prolog has. Moreover, stating it is a Prolog is not
> so much true then. That's the point as I can see it.
>
I got you. And this was my point, "declarative" for me, means some
declarations/restrictions about answer/answers. No exact algorithm: you
can even don't know how this is evaluated/executed. You only find some
relations and declare them. And set of solvers tries to find solutions.
So, modern Prolog/Logic systems are Prolog as DSL and set of solvers,
right. For example, to find factorial as well as it's argument, you need
to implement CLP library in Haskell explicitly (if you want to use CLP
way). This is the Haskell tradition. Sure, you can do it in Python, in C
(sure, such libraries already exist). But it's not declarative
tradition: predicates calculus is based on backtracking and variables
unification. Haskell, like Scheme is based on lambda calculus. So,
evaluation is totally different.
But more interesting here (regarding to Bool subj) is that Haskell can
return to you 120 as factorial result, but Prolog will answer you (if it
finds several results) "do you need next one?" and *result in Prolog is
"Yes."*. This is important. Which can be imagine in terms of Haskell
like you have not top-level `IO ()` but some `LogicMonad ()`. And all
evaluations in Haskell will lead to Boolean (OK, truth/lie/yes/no)
result. Evaluated (integers/floats/etc) result must be returned as
output variables (your factorial is: `factorial(+N, -F)` i.e. it's
one-directional only, so all functions in such Haskell also can return
results in some reference/output var and evaluated to Bool). I can
imagine this. Also if result is "No.", output variables unifications
(bindings - in Haskell terms) will be dropped out. Unfortunately I dont
know Curry and absolutely can not say: is it implemented in such way.
But I'm sure that it's possible :)
Joachim pointed out "cut" operation which leads to more effective code,
but eliminates pure logic constructs. There are "green cuts" (does not
change semantic) and "red cuts" and this shows that practical real world
languages mostly are not pure functional/pure logical.
But there is another point: it makes sense to have pure logical
application which can be driven from C# or Java application (there are
such puzzles and other games, on Android, Windows, tables/plane
schedulers, expert systems, etc), but I can not imagine why I'll call
for example, Haskell from the Java, because their area mostly are
intersected in contrast with Java/Prolog, for example. This is some
marker too, about which languages have similar "nature".
I have already agreed that are possible another classifications
coordinates as well as it's difficult to classify some languages because
they are totally hybrid (I remember yet another such: Racket, Oz/Mozart).
PS. I'm application developer only, not researcher, but I'm absolutely
sure: there are people in the list which are totally in the subject,
even may be some of them are devs of Curry or Mercury for example, and
maybe they are laughing at me and my naive intuitions now :)
> And it has nothing to do with Haskell extensions. In Haskell, the
> principle remains the same, though.
>
> Dušan
>
> On pondělí 9. července 2018 10:22:15 CEST you wrote:
>
> > Hello, Dušan!
>
> >
>
> > > This is not Prolog, it is a Prolog with CLP extension over integers.
>
> >
>
> > as well as Haskell has a lot of extensions. I mentioned CLP as solver
>
> > but modern Prologs is not ISO only and has a lot of solvers (CHR,
>
> > different CLP, FuzzyLogic, Tabulating, etc). Actually CLP(x) in included
>
> > in most modern implementations.
>
> >
>
> > 09.07.2018 10:58, Dušan Kolář wrote:
>
> > > Hello PY/Paul,
>
> > >
>
> > > You are using misleading arguments!
>
> > >
>
> > > This is not Prolog, it is a Prolog with CLP extension over integers.
>
> > >
>
> > > > factorial(0, 1).
>
> > > >
>
> > > > factorial(N, F) :-
>
> > > >
>
> > > > N #> 0,
>
> > > >
>
> > > > N1 #= N - 1,
>
> > > >
>
> > > > F #= N * F1,
>
> > > >
>
> > > > factorial(N1, F1).
>
> > > >
>
> > > >
>
> > > >
>
> > > > I can call it: factorial(5, X) => X=120.
>
> > > >
>
> > > > But also: factorial(X, 120) => X=5.
>
> > >
>
> > > Pure Prolog is:
>
> > >
>
> > > factorial(0, 1) :- !.
>
> > >
>
> > > factorial(N, F) :-
>
> > >
>
> > > NN is N - 1,
>
> > >
>
> > > factorial(NN, FF),
>
> > >
>
> > > F is FF * N.
>
> > >
>
> > > which is a function, not a relation, as you write.
>
> > >
>
> > > Dušan Kolář
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180709/d3dc68e1/attachment.html>
More information about the Haskell-Cafe
mailing list