Introduce a Haskell church pair coding for polymorphic λ-calculus / System F

I want to implement Church pair coding in polymorphic lambda calculus in Haskell.

On page 77, section 8.3.3 Peter Selinger's notes on lambda calculus , he gives the construction of a Cartesian product of two types as

A × B = ∀α. (A → B → α) → α
⟨M, N⟩ = Λα.λf A → B → α .fMN

For another source, on page 54, section 4.2.3 Dider Remy's notes on the lambda calculus , he defines the church coding of steam in the polymorphic λ-calculus / system F as

Λα₁.Λα₂.λx₁: α₁.λx₂: α₂.Λβ.λy: α₁ → α₂ → β. y x₁ x₂

I think Remy says the same thing, in more detail, like Selinger.

In any case, according to Wikipedia, the type system for Haskell is based on System F , so I hope it is possible to implement Church coding directly in Haskell. I have:

pair :: a->b->(a->b->c)->c
pair x y f = f x y

but I was not sure how to make predictions.

Λα.Λβ.λp α × β .pα ( α .λy β .x)

Am I using Haskell forallto quantify a lambda type quantifier?

This is basically the same as my previous question , but in Haskell instead of Swift. I thought that additional context and a change of place could make it more reasonable.

+4
2

, , ; , Rémy ⟨-, -⟩, M N ( x₁ x₂) (α₁ α₂); - ⟨M, N⟩ β y, Selinger α f.

, , . ∀, Λ, → λ Haskell. , ∀ Λ , → λ . Haskell-land ,

          System F                             Haskell
Terms (e)     :  Types (t)        Terms (e)       ::  Types (t)
────────────────────────────────────────────────────────────────
λx:t₁.(e:t₂)  :  t₁ → t₂          \x::t₁.(e::t₂)  :: t-> t
Λα.(e:t)      :  ∀α.t             (e::t)          :: forall α. t

: → ->, λ \. ∀ Λ?

Haskell ∀s . , ( ), . ,

id :: a -> a

id: ∀α.α → α

System F. ExplicitForAll :

{-# LANGUAGE ExplicitForAll #-}
id :: forall a. a -> a

, , Haskell ; , System F- forall . RankNTypes. , Haskell

{-# LANGUAGE RankNTypes, TypeOperators #-}

( .)

, , ×. Haskell **, ( ×, ).

A × B = ∀α. (A → B → α) → α

Haskell

type a ** b = forall α. (a -> b -> α) -> α

,

pair :: a -> b -> a ** b
pair x y f = f x y

Λs? F ⟨M, N⟩, pair !

, : Haskell Λs , , . , , , . , , Haskell forall System F ∀, Λ System F.

, ()

proj₁ = Λα.Λβ.λp: α × β.p α (λx: α.λy: β.x)

Haskell, Λs ( eliding type),

proj₁ = \p. p (\x y -> x)

proj₁ p = p (\x _ -> x)

F

proj₁: ∀α.∀β. α × β → α

,

proj₁: ∀α.∀β. (∀γ. Α → β → γ) → α

, Haskell

proj₁ :: α ** β -> α

proj₁ :: (forall γ. α -> β -> γ) -> α

, α β ,

proj₁ :: forall α β. (forall γ. α -> β -> γ) -> α

proj₂: ∀α.∀β. α × β → β
proj₂ = Λα.Λβ.λp: α × β.p β (λx: α.λy: β.y)

proj₂ :: α ** β -> β
proj₂ p = p (\_ y -> y)

, , : -)


¹ , Λs Haskell!

² , Λs, , . :

id :: a -> a
id x = x :: a

,

id :: forall a. a -> a
id x = x :: forall b. b

, , . , ScopedTypeVariables; , forall, . , ,

id :: forall a. a -> a
id x = x :: a

.

+8

Λα.Λβ.λp:α×β.p α (λx:α.λy.x)

, , :

λp:α×β.px:α.λy.x)

Haskell :

\p -> p (\x y -> x)
+1

Source: https://habr.com/ru/post/1615458/


All Articles