unification

Deriving the type of (foldr (.))

◇◆丶佛笑我妖孽 提交于 2019-12-12 01:33:17
问题 I'm trying to manually derive the type of (foldr (.)) foldr :: (a1 -> b1 -> b1) -> b1 -> [a1] -> b1 (.) ::(b2 -> c2) -> (a2 -> b2) -> a2 -> c2 Then: a1 ~ (b2 -> c2) b1 ~ (a2 -> b2) b1 ~ a2 So I get that (foldr (.)) :: (a2 -> b2) -> [(b2 -> c2)] -> (a2 -> b2) But GHCi returns: :t (foldr (.)) :: (a -> b) -> [b -> b] -> a -> b Why b2 and c2 are the same? Thanks, Sebastián. 回答1: If you look at the type of (.) as (b2 -> c2) -> (a2 -> b2) -> (a2 -> c2) then b1 ~ (a2 -> b2) b1 ~ (a2 -> c2) so (b2 ~

Function with type a -> b in Haskell?

雨燕双飞 提交于 2019-12-11 00:52:37
问题 Is there any kind of function in Haskell that has type a -> b ? That means, is it possible to write a function such that f :: a -> b ? I don't think a function like that exists for the following reason: suppose that we found f where f :: a -> b , what would f 2 produce? a value of type b , but what is b since Haskell cannot infere (I think) it from the arguments I gave? Is this correct? Otherwise, can you give me an example of such a function? 回答1: Barring ⊥ ( bottom value – undefined etc.),

Given a substitution S and list Xs, how to apply S to Xs

十年热恋 提交于 2019-12-10 21:03:39
问题 Suppose I have a substitution S and list Xs , where each variable occurring in Xs also occurs in S . How would I find the list S(Xs) , i.e., the list obtained by applying the substitution S to the list Xs . More concretely, I have a set of predicates and DCG rules that look something like pat(P) --> seg(_), P, seg(_). seg(X,Y,Z) :- append(X,Z,Y). If I attempt to match a pattern P with variables against a list, I receive a substitution S : ?- pat([a,X,b,Y],[d,a,c,b,e,d],[]). X = c, Y = e I

AI: Partial Unification in Open-World Reference Resolution

做~自己de王妃 提交于 2019-12-10 10:59:22
问题 When performing reference resolution on predicates describing the semantics of dialogue expressions, I need to be able to allow for partial unification due to working in an open world. For example, consider the following scenario: There is a blue box in front of you. We refer to this blue box using the id 3 . A set of predicates box(x)^blue(x) can easily resolve to the blue box you know about. Making this query will return 3 A set of predicates ball(x)^yellow(x) will not resolve to anything.

Prolog is vs = with lists

与世无争的帅哥 提交于 2019-12-10 01:52:27
问题 Why does this fail L is [1,2,3,4] , and this works: L = [1,2,3] ? But L is 1 , and L = 1 both work the same. 回答1: is should only be used when evaluating arithmetic operations on the right-hand side. i.e.: X is 1 + 2 + 3 is/2 evaluates the right-hand structure as an arithmetic expression. If it is not a valid arithmetic expression or a number, is/2 fails. Otherwise, the number to which the arithmetic expression evaluted is unified with the [presumably] unbound left-hand value. 来源: https:/

Custom data structure syntax in Prolog

萝らか妹 提交于 2019-12-07 14:21:08
问题 In Prolog, [H|T] is the list that begins with H and where the remaining elements are in the list T (internally represented with '.'(H, '.'(…)) ). Is it possible to define new syntax in a similar fashion? For example, is it possible to define that [T~H] is the list that ends with H and where the remaining elements are in the list T , and then use it as freely as [H|T] in heads and bodies of predicates? Is it also possible to define e.g. <H|T> to be a different structure than lists? 回答1: One

Generating run time proofs with type predicates in Idris

狂风中的少年 提交于 2019-12-06 23:05:22
问题 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 example, defining the digits [0-9] like this: data Digit : Char -> Type where Zero : Digit '0' One : Digit '1' Two : Digit '2' Three : Digit '3' Four : Digit '4' Five : Digit '5' Six : Digit '6' Seven : Digit '7' Eight : Digit '8' Nine : Digit '9'

AI: Partial Unification in Open-World Reference Resolution

那年仲夏 提交于 2019-12-06 06:40:19
When performing reference resolution on predicates describing the semantics of dialogue expressions, I need to be able to allow for partial unification due to working in an open world. For example, consider the following scenario: There is a blue box in front of you. We refer to this blue box using the id 3 . A set of predicates box(x)^blue(x) can easily resolve to the blue box you know about. Making this query will return 3 A set of predicates ball(x)^yellow(x) will not resolve to anything. This is fine. But now consider ball(x)^yellow(x)^box(y)^blue(y)^behind(x,y) that is, the yellow ball

Custom data structure syntax in Prolog

拥有回忆 提交于 2019-12-06 02:39:32
In Prolog, [H|T] is the list that begins with H and where the remaining elements are in the list T (internally represented with '.'(H, '.'(…)) ). Is it possible to define new syntax in a similar fashion? For example, is it possible to define that [T~H] is the list that ends with H and where the remaining elements are in the list T , and then use it as freely as [H|T] in heads and bodies of predicates? Is it also possible to define e.g. <H|T> to be a different structure than lists? One can interpret your question literally. A list-like data structure, where accessing the tail can be expressed

Simplest example of need for “unification” in type inference

随声附和 提交于 2019-12-04 14:28:41
I'm trying to get my head around how type inference is implemented. In particularly, I don't quite see where/why the heavy lifting of "unification" comes into play. I'll give an example in "pseudo C#" to help clarify: The naive way to do it would be something like this: Suppose you "parse" your program into an expression tree such that it can be executed with: interface IEnvironment { object lookup(string name); } interface IExpression { // Evaluate this program in this environment object Evaluate(IEnvironment e); } So something like "Multiplication" might be implemented with: class Multiply :