Layout Options
Which layout option do you want to use?
Wide
Boxed
Color Schemes
Which theme color do you want to use? Select from here.
Reset color
Reset Background
Forums
New posts
Trending
Random
What's new
New posts
Latest activity
Rules
Libraries
New Audios
New Comments
Search Profile Audios
Clubs
Public Events
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Trending
Random
Menu
Log in
Register
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Forums
Boards
/g/ - Technology
A vision for relational programming in miniKanren
Message
<blockquote data-quote="deaf_judger" data-source="post: 66419" data-attributes="member: 390"><p><strong><span style="font-size: 22px">[PLAIN]Introduction[/PLAIN]</span></strong></p><p> [PLAIN]MiniKanren is an embedded constraint logic programming language designed for writing programs as [/PLAIN]<strong>[PLAIN]relations[/PLAIN]</strong>[PLAIN], rather than as functions or procedures. Unlike a function, a miniKanren relation makes no distinction between its inputs and outputs, leading to a variety of fascinating behaviors. For example, an interpreter written as a relation can also perform code synthesis, symbolic execution, and many other tasks. Core miniKanren has only 3 operators:</p><p> [/PLAIN]</p><p></p><p> <ol> <li data-xf-list-type="ol">[PLAIN]Unification: a two-way pattern matcher. It can be thought of as a type of equality operator. It matches variables on both sides.<br /> [/PLAIN]<br /> <br /> [CODE]<br /> [== 5 5]<br /> [/CODE]<br /> [PLAIN]This asserts that 5 is equal to 5, and will return [/PLAIN]`False' [PLAIN]if it isnt. However, if a variable we dont know like `(== x 5)` is put in, x is also 5. This is an assertion. Just like the lisp I am building, each line is seperate. `(eq x 5) and (eq x 6)` is not inconsistent, because they are different branches.<br /> [/PLAIN]<br /> </li> <li data-xf-list-type="ol">`fresh'[PLAIN]: fresh introduces scoped logic variables; goals inside a fresh form are implicitly conjoined.<br /> [/PLAIN]<br /> </li> <li data-xf-list-type="ol">`conde'[PLAIN]: Disjunction. This is similar to lisps [/PLAIN]`cond' [PLAIN]operator. It allows us to get multiple answers. We can see the result of each clause independently. Each clause represents an alternative logical branch; results are interleaved fairly during search.<br /> [/PLAIN]<br /> <br /> [CODE]<br /> (fresh (y)<br /> (conde<br /> ((== x 5))<br /> ((== x 6))<br /> )<br /> [/CODE]<br /> [PLAIN]Will give [/PLAIN]`True'[PLAIN], and [/PLAIN]`True'[PLAIN]. Although the information appears inconsistent.<br /> [/PLAIN]<br /> </li> </ol><p></p><p></p><p></p><p><strong><span style="font-size: 22px">[PLAIN]Representing Syntax[/PLAIN]</span></strong></p><p> [PLAIN]To move beyond simple scalars (like 5 or 6), we use recursive relations to define grammars. A Lambda Calculus term consists of three parts: Variables, Abstractions (Lambdas), and Applications.</p><p> [/PLAIN]</p><p></p><p> [CODE]</p><p> x #variable. . We use the symbolo constraint to ensure a logic variable represents a scheme symbol.</p><p> \lambda x. y #abstraction</p><p> (f arg) # application</p><p> [/CODE]</p><p></p><p></p><p></p><p><strong><span style="font-size: 22px">[PLAIN]Divergent Search[/PLAIN]</span></strong></p><p> [PLAIN]Because these are relations, we can use the same code for three distinct purposes by changing which parts of the call are "logic variables" (unknowns).</p><p> [/PLAIN]</p><p></p><p> <ul> <li data-xf-list-type="ul">`(LC-syn '(lambda (x) x))' [PLAIN]Returns Success.<br /> [/PLAIN]<br /> </li> <li data-xf-list-type="ul">`(LC-syn q)' [PLAIN]Returns an infinite stream of all possible valid Lambda Calculus terms.<br /> [/PLAIN]<br /> </li> <li data-xf-list-type="ul">`(LC-syn '(lambda (x) ,q))' [PLAIN]and this fills the hole with valid bodies.<br /> [/PLAIN]<br /> </li> </ul><p></p><p></p><p></p><p><strong><span style="font-size: 22px">[PLAIN]Type Inference and the Turnstile[/PLAIN]</span></strong></p><p> [PLAIN]([/PLAIN]$\Gamma \vdash e : \tau$[PLAIN]) The "Vision" concludes by showing that an interpreter/type-checker written relationally can perform type synthesis.</p><p> [/PLAIN]</p><p></p><p> <ul> <li data-xf-list-type="ul">[PLAIN]Environment ([/PLAIN]$\Gamma$[PLAIN]): A mapping of variables to types.<br /> [/PLAIN]<br /> </li> <li data-xf-list-type="ul">[PLAIN]Expression ([/PLAIN]$e$[PLAIN]): The program code.<br /> [/PLAIN]<br /> </li> <li data-xf-list-type="ul">[PLAIN]Type ([/PLAIN]$\tau$[PLAIN]): The resulting type (e.g., Int, Bool, or a function type).<br /> [/PLAIN]<br /> </li> </ul><p> [PLAIN]Now, if you provide an expresion, it returns the type. If you provide a type, it generates all expressions that inhabit that type. This is achieved through the turnstile relation which recursively matches the structure of the expression against the typing rules of the language.</p><p> [/PLAIN]</p><p></p><p></p><p></p><p><strong><span style="font-size: 22px">[PLAIN]References[/PLAIN]</span></strong></p><p> Erlang Solutions, ed. 2015. /A Vision for Relational Programming in</p><p> miniKanren - William E. Byrd/. Directed by Erlang</p><p> Solutions. <[MEDIA=youtube]8gh4Ald4yZQ[/MEDIA]>.</p></blockquote><p></p>
[QUOTE="deaf_judger, post: 66419, member: 390"] [B][SIZE=6][PLAIN]Introduction[/PLAIN][/SIZE][/B] [PLAIN]MiniKanren is an embedded constraint logic programming language designed for writing programs as [/PLAIN][B][PLAIN]relations[/PLAIN][/B][PLAIN], rather than as functions or procedures. Unlike a function, a miniKanren relation makes no distinction between its inputs and outputs, leading to a variety of fascinating behaviors. For example, an interpreter written as a relation can also perform code synthesis, symbolic execution, and many other tasks. Core miniKanren has only 3 operators: [/PLAIN] [LIST=1] [*][PLAIN]Unification: a two-way pattern matcher. It can be thought of as a type of equality operator. It matches variables on both sides. [/PLAIN] [CODE] [== 5 5] [/CODE] [PLAIN]This asserts that 5 is equal to 5, and will return [/PLAIN]`False' [PLAIN]if it isnt. However, if a variable we dont know like `(== x 5)` is put in, x is also 5. This is an assertion. Just like the lisp I am building, each line is seperate. `(eq x 5) and (eq x 6)` is not inconsistent, because they are different branches. [/PLAIN] [*]`fresh'[PLAIN]: fresh introduces scoped logic variables; goals inside a fresh form are implicitly conjoined. [/PLAIN] [*]`conde'[PLAIN]: Disjunction. This is similar to lisps [/PLAIN]`cond' [PLAIN]operator. It allows us to get multiple answers. We can see the result of each clause independently. Each clause represents an alternative logical branch; results are interleaved fairly during search. [/PLAIN] [CODE] (fresh (y) (conde ((== x 5)) ((== x 6)) ) [/CODE] [PLAIN]Will give [/PLAIN]`True'[PLAIN], and [/PLAIN]`True'[PLAIN]. Although the information appears inconsistent. [/PLAIN] [/LIST] [B][SIZE=6][PLAIN]Representing Syntax[/PLAIN][/SIZE][/B] [PLAIN]To move beyond simple scalars (like 5 or 6), we use recursive relations to define grammars. A Lambda Calculus term consists of three parts: Variables, Abstractions (Lambdas), and Applications. [/PLAIN] [CODE] x #variable. . We use the symbolo constraint to ensure a logic variable represents a scheme symbol. \lambda x. y #abstraction (f arg) # application [/CODE] [B][SIZE=6][PLAIN]Divergent Search[/PLAIN][/SIZE][/B] [PLAIN]Because these are relations, we can use the same code for three distinct purposes by changing which parts of the call are "logic variables" (unknowns). [/PLAIN] [LIST] [*]`(LC-syn '(lambda (x) x))' [PLAIN]Returns Success. [/PLAIN] [*]`(LC-syn q)' [PLAIN]Returns an infinite stream of all possible valid Lambda Calculus terms. [/PLAIN] [*]`(LC-syn '(lambda (x) ,q))' [PLAIN]and this fills the hole with valid bodies. [/PLAIN] [/LIST] [B][SIZE=6][PLAIN]Type Inference and the Turnstile[/PLAIN][/SIZE][/B] [PLAIN]([/PLAIN]$\Gamma \vdash e : \tau$[PLAIN]) The "Vision" concludes by showing that an interpreter/type-checker written relationally can perform type synthesis. [/PLAIN] [LIST] [*][PLAIN]Environment ([/PLAIN]$\Gamma$[PLAIN]): A mapping of variables to types. [/PLAIN] [*][PLAIN]Expression ([/PLAIN]$e$[PLAIN]): The program code. [/PLAIN] [*][PLAIN]Type ([/PLAIN]$\tau$[PLAIN]): The resulting type (e.g., Int, Bool, or a function type). [/PLAIN] [/LIST] [PLAIN]Now, if you provide an expresion, it returns the type. If you provide a type, it generates all expressions that inhabit that type. This is achieved through the turnstile relation which recursively matches the structure of the expression against the typing rules of the language. [/PLAIN] [B][SIZE=6][PLAIN]References[/PLAIN][/SIZE][/B] Erlang Solutions, ed. 2015. /A Vision for Relational Programming in miniKanren - William E. Byrd/. Directed by Erlang Solutions. <[MEDIA=youtube]8gh4Ald4yZQ[/MEDIA]>. [/QUOTE]
Insert quotes…
Name
Verification
Post reply
Forums
Boards
/g/ - Technology
A vision for relational programming in miniKanren
Top