Skip to content

added lambda interpreter solution & excersizes solutions#3

Open
AnNyiiik wants to merge 15 commits intomainfrom
HW_3
Open

added lambda interpreter solution & excersizes solutions#3
AnNyiiik wants to merge 15 commits intomainfrom
HW_3

Conversation

@AnNyiiik
Copy link
Owner

No description provided.

\begin{math}((\lambda a. (\lambda b.b \ b) \ (\lambda b.b \ b))\ b)\ ((\lambda c.(c\ b)) \ (\lambda a. a)) \ \rightarrow_{\beta} ((\lambda b.b \ b) \ (\lambda b.b \ b)) \ ((\lambda c.(c\ b)) \ (\lambda a. a)) \rightarrow_{\beta} ((\lambda b.b \ b) \ (\lambda b.b \ b)) ((\lambda a. a) \ b) \ \rightarrow_{\beta} ((\lambda b.b \ b) \ (\lambda b.b \ b)) \ b
\section{SKK}
\begin{math}((\lambda x\ y\ z.x\ z\ (y\ z))\ (\lambda x\ y . x))\ (\lambda x\ y . x)\ \rightarrow_{\alpha} ((\lambda x\ y\ z.x\ z\ (y\ z))\ (\lambda a\ b . a))\ (\lambda m\ p . m)\ \rightarrow_{\beta} ((\lambda y\ z.(\lambda a \ b.a)\ z\ (y\ z))\ (\lambda m\ p . m)\ \rightarrow_{\beta} \lamda z.(\lambda a \ b.a)\ z \ ((\lamda m\ p. m)\ z)) \ \rightarrow{\beta} \lambda z.z\end{math}
\end{document}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Компилится с ошибками, стоит от них избавиться.
И в SKK чем дальше, тем хуже форматирование: пропали некоторые лямбды, символы betta-редукции увеличиваются. Надо привести в читабельный вид, чтобы каждый новый терм после применения правила оказывался на новой строке

module Program =

[<EntryPoint>]
let main _ = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я предпочитаю это не писать, а делать GenerateProgramFile>true</GenerateProgramFile>

[<Test>]
let Test1 () =
Assert.Pass()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net7.0 помер давно

module Program =

[<EntryPoint>]
let main _ = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Где-то я это уже видел

Comment on lines +20 to +21
Assert.AreEqual(expected, result)
[<Test>]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Assert.AreEqual(expected, result)
[<Test>]
Assert.AreEqual(expected, result)
[<Test>]

И ниже.

@@ -0,0 +1,63 @@
namespace Lambda_Interpreter

module lambdaInterpreter =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Надо комментарии

| Abstraction of string * LambdaTerm
| Application of LambdaTerm * LambdaTerm

type Substitution = (string * LambdaTerm) list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😕

| Variable name ->
if List.contains name boundVariables then
let newName = name + "'"
Variable newName

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему newName не может быть в boundVariables?

| Variable _ -> term
| Abstraction (arg, body) -> Abstraction (arg, betaReduce body)
| Application (Abstraction (arg, body), argValue) ->
let substitutedBody = substitute [(arg, argValue)] body

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я так и не понял, зачем substitute список принимает

match term with
| Variable name -> name
| Abstraction (arg, body) -> sprintf "(λ%s.%s)" arg (toString body)
| Application (func, arg) -> sprintf "(%s %s)" (toString func) (toString arg) No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI ругается, что main-а нет. Собирали бы библиотеку, не ругался бы

open HW_3.LambdaInterpreter

[<Test>]
let ``isFreeVariable: check free variable`` () =

This comment was marked as resolved.

| Variable v ->
if v = variable then
if not (isFreeVariable v value) then
let newName = v + "'"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А правда ли, что newName гарантированно не входит свободно в value? Тут и ниже.

@@ -0,0 +1,80 @@
namespace HW_3

module LambdaInterpreter =

This comment was marked as resolved.

| Abstraction of string * LambdaTerm
| Application of LambdaTerm * LambdaTerm


This comment was marked as resolved.


let expr =
Application (
Abstraction ("x", (Abstraction("y", Application( Variable "x", Variable "y")))),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пробелы неконсистентно расставлены

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не исправлено



let isFreeVariable (variable: string) (expression: LambdaTerm) : bool =
let rec isFreeVariableReq (variable: string) (bounded : string list) (expression: LambdaTerm) : bool =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Req?

if v = oldName then Variable newName else term
| Abstraction (v, body) ->
if v = oldName then
if (isFreeVariable newName body) then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут скобки лишние

if (isFreeVariable newName body) then
Abstraction (newName, alphaConvert oldName newName body)
else
Abstraction (v, body)

This comment was marked as resolved.

| Abstraction (v, body) ->
if v = variable then
Abstraction (v, body)
elif not(isFreeVariable v value) then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif not(isFreeVariable v value) then
elif not (isFreeVariable v value) then

Скобки в F# не ограничивают список параметров, а обозначают границы одного параметра, так что с пробелом

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И почему not? Если переменная под лямбдой не входит свободно в подставляемый терм, её как раз можно не трогать, она ничего там не свяжет. В определении подстановки не так было

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Идеологически всё так, но оооочень неаккуратно

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На .NET 8 так и не удалось мигрировать? IRL Вы могли бы оказаться в забавной ситуации, когда Вы начинаете деплой в инфраструктуре заказчика, а там рантайм только .NET 8 и нет возможности сказать .NET 7 (например, по политикам безопасности). И программа вообще не запускается. И заказчик такой "Ну вот же, замечания с первой приёмки, целевую платформу поменять, почему не сделали?". И срыв приёмо-сдаточных испытаний, неустойка, позорное увольнение.


let expr =
Application (
Abstraction ("x", (Abstraction("y", Application( Variable "x", Variable "y")))),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не исправлено


module LambdaInterpreter =

/// <summary>The type which expresses the lambda-term.</summary>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В F#, кстати, более принято просто /// The type which expresses the lambda-term., без тэгов, где они не нужны.

Comment on lines +12 to +13
/// <param name="variable">The variable name.</param>
///<param name="expression">The lambda-term of an expression.</param>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут то есть пробел после ///, то нет

/// <param name="variable">The variable name.</param>
///<param name="expression">The lambda-term of an expression.</param>
///<returns>The truth if the variable is in the expression, otherwise false.</returns>
let rec isVaraibleInExpression (variable: string) (expression: LambdaTerm) : bool =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Опечатка в названии

///<param name="expression">The lambda-term of an expression.</param>
///<returns>The truth if the variable is bounded, otherwise false.</returns>
let isFreeVariable (variable: string) (expression: LambdaTerm) : bool =
let rec isFreeVariableRec (variable: string) (bounded : string list) (expression: LambdaTerm): bool =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bounded ("ограниченный") лучше переименовать в bound ("связанный")

| Application (e1, e2) ->
Application (substitute variable value e1, substitute variable value e2)

///<summary>Performes a one step of beta-reduction.</summary>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performs

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мелкие замечания остались, но Вы смогли победить переход на .NET 8 с CI, так что зачтена

let expr =
Application (
Abstraction ("x",
(Abstraction("y", Application( Variable "x", Variable "y")))),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну так и всё равно тут скобка с пробелом местами поменяны


module LambdaInterpreter =

///The type which expresses the lambda-term.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У Вас был выбор, либо вставить пробел везде, либо удалить везде. Вы выбрали неправильно (ну, не по стайлгайду) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants