Sign in to follow this  

Functional languages with Prolog style unification?

This topic is 4397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does such a thing exist? FP pattern matching is nice, but not as nice as Prolog's. For instance, if SML had unification the following function would be possible:
fun member([], item) = false
|   member(head::tail, head) = true
|   member(head::tail, item) = member(tail, item)
If this isn't possible, is there a reason? I suppose the unification algorithm itself is complicated, but Prolog manages it.

Share this post


Link to post
Share on other sites
Common Lisp plus CL Unification provides you with functional features and unification.

Your example is actually of pattern-matching. Unification is only one possible implementation of the solution.

One could use CL Unification to build a pattern-matching macro 'defmatcher':


(defmatcher member
((() ?item) t) ;; t is Common Lisp for true
(((?head . ?tail) ?head) nil) ;; nil is Common Lisp for false
(((?head . ?tail) ?item) (member ?tail ?item)))

(member '(a b c) 'a) -> t
(member '(a b c) 'd) -> nil



Share this post


Link to post
Share on other sites
I have no experience with logic programming so i do not know what the term "unification" exactly means, with my limited knowledge of SML i believe that code isn't valid as far i'm aware you can't have a matches like that.

There do exist "functional logic" paradigms, languages that combine only the logic features of Prolog and a functional language, one such example is the Curry language. Bare in mind that Curry's functional side is based off haskell, haskell differs from SML because it's a non-strict functional language (among other things).

Share this post


Link to post
Share on other sites
Quote:
Original post by Nathan Baum
Common Lisp plus CL Unification provides you with functional features and unification.

Your example is actually of pattern-matching. Unification is only one possible implementation of the solution.

One could use CL Unification to build a pattern-matching macro 'defmatcher':

*** Source Snippet Removed ***


Thanks, that appears to be what I'm looking for.

Share this post


Link to post
Share on other sites

This topic is 4397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this