Questions tagged [unification]

Unification, in computer science and logic, is an algorithmic process by which one attempts to solve the satisfiability problem. The goal of unification is to find a substitution which demonstrates that two seemingly different terms are in fact either identical or just equal.

Unification, in computer science and logic, is an algorithmic process by which one attempts to solve the satisfiability problem. The goal of unification is to find a substitution which demonstrates that two seemingly different terms are in fact either identical or just equal.

Unification is widely used in automated reasoning, logic programming and programming language type system implementation. In particular, it is widely used in type deduction for example in C++ templates type deduction or in functional language such as Scala/Ocaml/Haskell type synthesis.

Several kinds of unification are commonly studied: syntactic unification (for theories without any equations) and semantic unification (for non-empty equational theories).

See also

228 questions
9
votes
3 answers

Pattern matching equivalent variables in Haskell, like in Prolog

In prolog, we can do something like the following: myFunction a (a:xs) = ... This is, when the 1st argument of myFunction is the same as the first item of the list that's in the 2nd argument, this function will evaluate to .... My question now…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
8
votes
2 answers

`coerce` and instantiation of type variables

Consider the following GHCi session: >:set -XTypeApplications >import Data.Map.Strict >import GHC.Exts >newtype MySet a = MySet (Map a ()) >let member' :: Ord a => a -> MySet a -> Bool; member' = coerce member :21:57: error: *…
Sebastian Graf
  • 3,602
  • 3
  • 27
  • 38
8
votes
1 answer

Generating run time proofs with type predicates in Idris

I am using this type to reason about strings on which decidable parsing can be performed: data Every : (a -> Type) -> List a -> Type where Nil : {P : a -> Type} -> Every P [] (::) : {P : a -> Type} -> P x -> Every P xs -> Every P (x::xs) For…
Vic Smith
  • 3,477
  • 1
  • 18
  • 29
7
votes
2 answers

GHC rejects ST monad code as unable to unify type variables?

I wrote the following function: (.>=.) :: Num a => STRef s a -> a -> Bool r .>=. x = runST $ do v <- readSTRef r return $ v >= x but when I tried to compile I got the following error: Could not deduce (s ~ s1) from the context (Num a) bound by…
user1023733
  • 805
  • 5
  • 14
7
votes
1 answer

Can't deduce f = f₁ from f x = f₁ y?

{-# LANGUAGE GADTs #-} data Foo x y where Composition :: Foo b c -> Foo a b -> Foo a c FMap :: Functor f => (a->b) -> Foo (f a) (f b) asFunction :: Foo a b -> a->b asFunction (FMap m) = fmap m -- asFunction (Composition (FMap m) (FMap n)) =…
leftaroundabout
  • 117,950
  • 5
  • 174
  • 319
7
votes
6 answers

Why has "map (filter fst)" the type "[[(Bool, a)]] -> [[(Bool, a)]]"?

I'm trying to understand why the function map (filter fst) has the type [[(Bool, a)]] -> [[(Bool, a)]] How can "filter fst" work if filter must receive a function which returns a Bool-Type and fst just returns the first element of a tuple?…
6
votes
2 answers

Extending unification, SICStus-style

I want to understand SICStus-style extensible unification. The User's Manual on library(atts) states that: Module:verify_attributes(-Var, +Value, -Goals) hook ... verify_attributes/3 may invoke arbitrary Prolog goals, but Var should not be bound…
repeat
  • 18,496
  • 4
  • 54
  • 166
6
votes
1 answer

Prolog: Is f(X) = X unifiable or not?

My understanding of unification is a little patchy. I understand basic unification, but I'm having issues getting my head round terms which are not unifiable. I was watching a youtube tutorial on unification which stated if a variable is trying to…
Wolff
  • 1,051
  • 3
  • 18
  • 31
6
votes
3 answers

Real world example of Unification in First Order Logic?

I know this is only part of a programming question, but at the moment, I'm doing a little bit of logic programming. One thing I still don't understand correctly is Unification in First Order Logic. I read the Wikipedia article and it is more or less…
anon
5
votes
2 answers

Deleting all members of a list without unification in Prolog

Possible Duplicate: Prolog delete: doesn't delete all elements that unify with Element In Prolog if you write this: delete([(1,1),(1,2),(1,1),(3,4)],(1,_),L). the result will be: L = [ (1, 2), (3, 4)]. What is normal because the _ variable…
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
5
votes
1 answer

How does instantiation of higher-rank types and subsumption interact during unification?

A function type is higher-rank if a quantifier appears in contravariant position: f :: (forall a. [a] -> b) -> Bool Regarding the unification of such a type the type variable a is more rigid than b, because the following instantiation rules…
5
votes
3 answers

How can Prolog derive nonsense results such as 3 < 2?

A paper I'm reading says the following: Plaisted [3] showed that it is possible to write formally correct PROLOG programs using first-order predicate-calculus semantics and yet derive nonsense results such as 3 < 2. It is referring to the fact…
MWB
  • 11,740
  • 6
  • 46
  • 91
5
votes
1 answer

Feature structure unification in minikanren

How would one define a feature structure unification and subsumption in minikanren if we represent feature structures with lists? The general behaviour would be something like this (I think): (run* (q) (unifyo '(a b) '(a b) q))) => (a b) (run* (q)…
5
votes
1 answer

Instantiate type variable in Haskell

EDIT: Solved. I was unware that enabling a language extension in the source file did not enable the language extension in GHCi. The solution was to :set FlexibleContexts in GHCi. I recently discovered that type declarations in classes and instances…
emi
  • 5,380
  • 1
  • 27
  • 45
5
votes
3 answers

What is a unification algorithm?

Well I know it might sound a bit strange but yes my question is: "What is a unification algorithm". Well, I am trying to develop an application in F# to act like Prolog. It should take a series of facts and process them when making queries. I was…
Andry
  • 16,172
  • 27
  • 138
  • 246
1
2
3
15 16