haskell,types,ghci,unification

The constraint a1 -> Bool ~ a2 -> Bool can be broken down to a1 ~ a2 and the obviously true Bool ~ Bool So you have a1 ~ a2. You already know that x is a1, xs is [a2] and, thanks to filter, the result type is [a2]. Therefore,...

logic,artificial-intelligence,substitution,unification,unify

Basically, Theta is a substitution that can make some set of terms you know to be true (the p's in the KB) equal to the ps in the rule, then you can conclude that q' (q with the same Theta applied to it) is also true. If that q' isn't...

parsing,unification,idris,decidable

The error message is correct: you provided a value of type Type, but you need a value of type p '0'. You are also correct that p is of type Char -> Type, and therefore that p '0' is of type Type. However, p '0' is not of type p...

Short story The Prolog book is probably old. The Prolog interpreter is most likely a lot newer. Also, your interpreter is smart enough to write a cyclic term very compactly. Longer story At the heart of Prolog's execution mechanism lies syntactic unification of terms. Unification has similarities with pattern matching....

haskell,typechecking,gadt,unification

This may be related to a feature left/right decomposition of coercions that was temporarily removed from GHC's type inference system in order to support more flexible ("unsaturated") type functions, and then reintroduced when it was found to have annoying effects like this.

Assume that _ is Y member(X, [Y|T]):- member(X, T). Then this is True regardless Y. Now you are "returning" member(X, T). In other words, you are discarding Y and "returning" member(X, T). _ means, whatever it is, ignore that variable. The _ is just like any other variable, except that...

haskell,types,ghci,unification

(flip .) is (.) flip, so: (.) :: (bx -> cx) -> (ax -> bx) -> ax -> cx flip :: (ay -> by -> cy) -> by -> ay -> cy In (.) flip, bx is ay -> by -> cy cx is by -> ay -> cy so...

algorithm,prolog,unification,iso-prolog

Third attempt. This is mainly a bugfix in a previous answer (which already had many modifications). Edit: 06/04/2015 When creating a more general term I was leaving both subterms as-is if either of them was a variable. Now I build a more general term for the "other" subterm in this...

Your correctly figured out the type of the (.) in (.) foldr. The (.) is applied to one argument (the foldr) so you can throw away the ((a2 -> b2 -> b2) -> (b2 -> [a2] -> b2)) and what remains is the type of (.) foldr: (a1 -> a2...

haskell,types,ghci,unification

Under any circumstances, which here implies: the function is never useful. This is actually a nice example of "theorems for free". Obviously, the type Ord t => [t] -> [a] doesn't make much sense, because the only list you can produce of a type [a] (you know nothing about a!)...

If you truly want a string, you should use double-quotes: X="'*'". If you want to make a symbol, you can use atom_codes( X, "'*'" ). ...

haskell,functional-programming,ocaml,type-inference,unification

data F f = F (f F) On GHC 7.10.1, I get the message: kind.hs:1:17: Kind occurs check The first argument of ‘f’ should have kind ‘k0’, but ‘F’ has kind ‘(k0 -> k1) -> *’ In the type ‘f F’ In the definition of data constructor ‘F’ In the...

haskell,types,ghci,unification

One way is to use asTypeOf:: a -> a -> a. As a function, asTypeOf isn't very interesting, but its type is nice: it forces its two arguments and its return type to unify. So: > :t asTypeOf (undefined :: Int -> Bool) (undefined :: a -> Bool) asTypeOf (undefined...

The approach below is not necessarily the easiest or fastest, but it's relatively systematic. Strictly speaking, you're looking for the type of \g -> (\ x -> let ys = (++) [x] (filter (curry g x) ys) in ys) (let and where are equivalent, but it's sometimes a little easier...

haskell,types,ghci,unification

In the final step, you mix up the argument oder. You unify b1 -> c1 with the type of map (:), but you should unify it with the type of foldr (++). More generally, you might want to learn how to debug such complicated calculations yourself. It is good that...

Your first answer, D = 1, Y = X accords with your first definition. I think you're expecting that when you quarry ?- test(func(X), Y, D). it should fail for the first definition, because the X and Y are different variables, but the first definition should only succeed if the...

The type checker won't reduce natToChar because it isn't total - this is basically to prevent you using some partially defined function to prove something which isn't true. If you're writing this to work on data which turns up at run-time, possibly what you need is Dec or Maybe: natToChar...

haskell,types,ghci,unification

If you look at the type of (.) as (b2 -> c2) -> (a2 -> b2) -> (a2 -> c2) then b1 ~ (a2 -> b2) b1 ~ (a2 -> c2) so (b2 ~ c2) then you can see the type of (foldr (.)) is (a2 -> b2) -> [(b2...

To start with the function fun xss = \f -> let ope x y = x . f . y in foldr1 ope xss I'll rewrite this as fun xss f = foldr1 ope xss where ope x y = x . f . y So we start with foldr1:...

haskell,types,ghci,unification

If we start with (.) :: (b -> c) -> (a -> b) -> (a -> c) zipWith :: (x -> y -> z) -> [x] -> [y] -> [z] uncurry :: (u -> v -> w) -> (u, v) -> w Then we match zipWith's type with (b ->...