Giter VIP home page Giter VIP logo

saga's Introduction

Coming soon ๐Ÿšง

saga's People

Contributors

tiansivive avatar

Stargazers

Domenic avatar

Watchers

 avatar  avatar

saga's Issues

Algebraic subtyping

Discussed in #38

Originally posted by tiansivive December 18, 2023
Incorporate Algebraic Subtyping to infer and typecheck singleton types, type unions and liquids

Monadic comprehensions

Proposed syntax:

let comprehension 
    = \xs -> yield (x + y) from {
      x <- xs if isEven |> (>5) 
      y <- range 0 x

      then take 5
      then group by y
    } using someMonadImpl

We take advantage of curly blocks to introduce then constructs, similar to haskell list comprehensions

We add if clauses (potentially unless too) to backcall, which get desugared to guards on the results of the backcall

Questions:
Do we need to ensure purity? Do we need to work only with monads?

A then statements could simply desugar to introducing a new code block scoped to all the variables of the current block.
For example:

yield (x + y) from {
  x <- xs
  y <- range 0 x

  then take 5
}

Would desugar to:

yield (x + y) from {
  return take 5 {
     x <- xs
     y <- range 0 x
     return (x,y)
  }
}

Consequently, one can do

yield (x + y) from {
  x <- xs
  y <- range 0 x

  (x', y') <- then take 5

  return (x' +1, y' +1)
}

Which desugars to

yield (x + y) from {
  (x', y') <- take 5 {
     x <- xs
     y <- range 0 x
     return (x,y)
  }
  return (x' +1, y' +1)
}

Kind check when evaluating types

-- | TODO:#Kinds we probably need some kind check here

-- | TODO:#Kinds we probably need some kind check here

-- | TODO:#Kinds we probably need some kind check here

-- | TODO:#Kinds we probably need some kind check here

Improve control flow type narrowing

Improve type subtype narrowing by resolving variance issues.

For example, in the expressions:

match x
  |  1    -> return x 
  |  "Hi" -> return x

Do we want to infer x as Int | String or 1 | "Hi"?
Similarly, do we keep subtypes in the match expression return type?

An option would be to preserve subtypes when no catch-all case is provided, which would be in line with totality/exhaustiveness, and generalize to supertypes (Int | String) when catch-all/default cases exist

Typed variadic arguments

Add a variadic param type, inspired by Typescript's rest params

Possible syntax:

fn: Int -> ...String -> Bool



> fn 1!         -- FnApp <fn> [TLit 1, TVariadic []]
> fn 1 "hello"! -- FnApp <fn> [TLit 1, TVariadic [TLit "hello"]]

Edge cases:

fn: ...String -> String -> Int


> fn "hello"!         -- FnApp <fn> [ TVariadic [], TLit "hello"]
> fn "hello" "world"! -- FnApp <fn> [ TVariadic [TLit "hello"], TLit "world"]

Fix inference generalization

Currently, inference generalizes types too early, during the initial AST traversal and constraint generation phase.
Propose moving generalization to after the solver has finished. This would prevent losing narrowed type information, crucial for refinements, which is currently broken.

Infer Purity constraints

  • Infer values as Pure by default
  • Default blocks to impure, unless they preserve purity via using clauses.
  • Investigate adding Purity constraints to type bindings and whether that overrules impure inference rules

Add Scope for type lambda evaluation

Currently evaluating/inferring type lambdas adds the param bindings to the global type vars environment.
What's needed is a similar approach to term level lambda evaluation, where we have a closure'd env, ie. a "Scope"!

Use associated types instead of a second type argument

Main use would be in the Substitution typeclass, but could perhaps be extended to:
* PolymorphicVar
* Inference: Perhaps removing the need for Classifier family
* Generalization & Instantiation
* Type Evaluation

Assignees: @tiansivive
Labels: Substituions, enhancement, Unification, Constraint Solver,
Milestone:

https://github.com/tiansivive/saga/blob/cc4e21b3fe78af8491ed42515b89cf95c040fe2f/src/Saga/Language/Typechecker/Solver/Substitution.hs#L14

Fix Singleton types inference for Liquid types

Singleton types are essentially subtypes of the Int, Bool and String primitive types. That causes inconsistencies dueing inference, especially for liquids, as we want to keep the most specific (the Singleton) type for refinements, and yet have it unify as the more general primitve.
To solve this, we should investigate also generating "proofs/witenesses" when dealing with singleton types, probably during unification, when binding to a type variable.

Evaluate type lambdas to TParametric

TConstructor vs TParametric vs TClosure

Need to remove the indecision regarding parametric types.
Currently, the notation MyType<Int> parses into TParametric, with the latter taking an array of the type arguments.

Instead, we should take advantage of Type Function Application expressions and enforce the following syntax:

MyType Int!

MyType would be be defined as:

//potentially allow/require `forall` annotation
type MyType = \a -> { value: a } // or whatever other output type.

and would be parsed as a TypeExpression. Evaluating this tyExpr will then result in a TParametric

eval (TLambda args body) = TParametric <first arg> <output type | recursive TParametric>

This enforces type arg currying and takes advantage of the same semantics as term level expressions and evaluation.

Preference for TParametric over TConstructor to not cause confusion with type constructors as defined by data declarations like:

data Maybe = \a -> Just: a | Nothing

Variables: Different constraints to restrict different constructors.

Right now, if both refinements and evidence implement an instance of Restricted, then a refinement var could be used where an evidence var is expected, and vice-versa

  • SUGGESTION: More type families - one for each.
  • SUGGESTION: One more elaborate type family: Context
  • QUESTION: How to implement a Context type family?

Assignees: @tiansivive,
Labels: Variables,bug enhancement, Typechecker, Constraint Solver, question,
Milestone:

https://github.com/tiansivive/saga/blob/cc4e21b3fe78af8491ed42515b89cf95c040fe2f/src/Saga/Language/Typechecker/Variables.hs#L40

Parse type level binary operations

** Liquid types **

Right now, we can parse something like

type Foo = a 
  where 
    a = Int,
    a | \x => 1 

Which is not very useful because we can't do arbitrary conditions.

Ideally we want to express refinements like

a | \x => x > 0

Function overloading

By taking advantage of type unions, we can introduce function overloading.

This can be useful for having different APIs, for example, curried vs uncurried versions or different parameter order for readability purposes

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.