Giter Site home page Giter Site logo

ollef / bidirectional Goto Github PK

View Code? Open in Web Editor NEW
128.0 9.0 11.0 15 KB

Haskell implementation of Dunfield and Krishnaswami's "Complete and easy bidirectional typechecking for higher-rank polymorphism"

License: BSD 3-Clause "New" or "Revised" License

Haskell 100.00%

bidirectional's People

Contributors

andraskovacs avatar andrewthad avatar ollef avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bidirectional's Issues

is the alpha-conversion in instantiation really necessary (InstLAIIR)?

Hi,

I'm currently implementing these algorithms, in ... Go, of all languages, and the results are as you'd expect. Having your work as a guide is extremely useful. Thank you.

In your implementation, you do alpha-conversion of \beta as part of InstLAIIR. The text doesn't make mention that this is necessary (though I can completely believe this was something that got cut to make a page limit). Did you come across cases where this is essential?

Does not subsume Hindley-Milner?

When trying:

(\x y -> x) ()

I got:

(TFun (TExists (TypeVar "'k")) TUnit,[CExistsSolved (TypeVar "'l") TUnit,CExists (TypeVar "'k")])

This is an invalid type since there is an unsolved existential. Which means typechecking fails for this short program, this doesn't seem right to me,

EDIT: 1s after posting this I realized that the same thing happens in Hindley-Milner, you have to re-generalize after application I guess.

"The impossible happened!"

Attempting to synthesize a type of (λx. x x) fails for obvious reasons, but attempting to synthesize the type with a type annotation -- λx. (x : ∀ a. a → a) x -- produces a "The impossible has happened!" error. Consider the following ghci session:

*Main> let ty = polytype $ TForall (TypeVar "a") (TFun (tvar "a") (tvar "a"))
*Main> run (EAbs x (EApp (EAnno (EVar x) ty) (EVar x)))
"typesynth([], λx. (x : ∀ a. a → a) x)
   typecheck([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a], ($a : ∀ a. a → a) $a, ∃ 'b)
      typesynth([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a], ($a : ∀ a. a → a) $a)
         typesynth([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a], $a : ∀ a. a → a)
            typecheck([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a], $a, ∀ a. a → a)
               typecheck([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a, 'c], $a, 'c → 'c)
                  typesynth([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a, 'c], $a)
                  =(∃ 'a, [▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a, 'c])
                  subtype([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a, 'c], ∃ 'a, 'c → 'c)
                     instantiateL([▶ 'a, ∃ 'a, ∃ 'b, $a : ∃ 'a, 'c], 'a, 'c → 'c)
                        instantiateR([▶ 'a, ∃ 'e, ∃ 'd, ∃ 'a = ∃ 'd → ∃ 'e, ∃ 'b, $a : ∃ 'a, 'c], 'c, 'd)
*** Exception: The impossible happened! instantiateR: ([▶ 'a, ∃ 'e, ∃ 'd, ∃ 'a = ∃ 'd → ∃ 'e, ∃ 'b, $a : ∃ 'a, 'c], 'c, 'd)
*Main> 

where run is defined in a file Main.hs as follows:

module Main where

import AST
import Context
import NameGen
import Pretty
import Type

import Control.Monad.State

run :: Expr -> String
run e = case runState (typesynth (context []) e) initialNameState of
  (context, _) -> pretty context

How to extend with type applications

Do you have any idea how to extend the system with type applications. I don't know how to extend the subtyping relation, because in general I don't know whether to compare the type applications covariantly or contravariantly. Is the only solution to fall back to unification (unifying foralls using alpha equality)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.