Git Product home page Git Product logo

coco's People

Contributors

barrucadu avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

coco's Issues

Merge type environments by unification, not equality

unifyAccum :: Bool -> (Maybe TypeEnv -> Maybe TypeEnv) -> [TypeRep] -> [TypeRep] -> Maybe TypeEnv
unifyAccum b f as bs = foldr go (Just []) (zip as bs) where
  go (tyA, tyB) (Just env) = do
    assignments <- f (unify' b tyA tyB)
    let env' = nub (env ++ assignments)
    guard $ all (\v -> length (filter ((==v) . fst) env') <= 1) tyvars
    pure env'
  go _ Nothing = Nothing

The nub / guard is too strict, it requires that type variables have equal assignments, rather than just unifying assignments. A better solution is a unifyTypeEnvs :: TypeEnv -> TypeEnv -> Maybe TypeEnv function which finds all clashes and attempts to unify them, continuing recursively if this introduces new constraints.

An arbitrary number of type variables

I've figured out a nice way to support an arbitrary number of type variables:

> :set -XDataKinds
> :set -XKindSignatures
> import Data.Proxy
> import Data.Typeable
> import GHC.TypeLits
> data TyVar (n :: Nat) = TyVar
> type A = TyVar 0
> let isTypeVar :: Typeable t => Proxy t -> Bool; isTypeVar p = fst (splitTyConApp (typeRep p)) == fst (splitTyConApp (typeRep (Proxy :: Proxy A)))
> isTypeVar (Proxy :: Proxy A)
True
> isTypeVar (Proxy :: Proxy Int)
False

The A, B, C, an D types can still be exported, but now if someone wants more they can have as many as they want.

Refinement symbol

There are two problems with the current syntax:

  1. -[- is not a valid Haskell operator name, because someone could do this:
instance Num a => Num [a] where
    fromIntegral n = [fromInteger n]
    a - b = [sum a - sum b]
  ...

> 3 -[- 6 ]
 9
  1. The real operator is actually read as "is refined by", not "refines". So it's backwards.

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.