GithubHelp home page GithubHelp logo

arianvp / generics-mrsop-diff Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 1.0 423 KB

Typesafe structural diffing of haskell datratypes using generics

License: Other

Haskell 54.46% Nix 1.72% Lua 35.22% Shell 5.78% CoffeeScript 2.82%

generics-mrsop-diff's Introduction

generics-mrsop-diff's People

Contributors

arianvp avatar victorcmiraldo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

victorcmiraldo

generics-mrsop-diff's Issues

Impossible to pattern match on Ctxs and discover _what_ constructor it is pointing to

Given the definition of Ctxs:

data Ctx :: (kon -> *) -> [*] -> [[Atom kon]] -> Nat -> * where
  Ctx :: Constr c n
      -> NPHole ki fam ix (Lkup n c)
      -> Ctx ki fam c ix
data Ctxs :: (kon -> *) -> [*] -> [[[Atom kon]]] -> Nat -> Nat -> * where
  Nil  :: Ctxs ki fam cs ix ix
  Cons :: (IsNat ix , IsNat a , IsNat b)
       => Ctx ki fam (Lkup ix cs) b -> Ctxs ki fam cs a ix
       -> Ctxs ki fam cs a b

and me wanting to visualize the Constructor the hole is pointing to

We will need to somehow call :

  datatypeInfo :: (IsNat ix)
               => Proxy fam -> SNat ix -> DatatypeInfo (Lkup ix codes)

However, When we pattern match on Cons, and want to call datatypeInfo,
How do we ever discover the SNat ix that we need to supply? Because
ix is existential in Ctxs we can't call getSNat (Proxy :: Proxy ix)

So there is no what for us to visualize the Constructor inside Ctx

case ctxs of
  Nil -> ""
  Cons (Ctx c h) ctxs ->  
    constructorName (constrInfoLkup c (datatypeInfo (Proxy :: Proxy fam)) ????)

Type error while trying to visualize Zippers

I'm trying to deconstruct and pattern match on a Ctxs and Ctx in order to visualize a zipper, but Haskell is giving me a hard time.

visualizeNPHole ::
(IsNat ix, Show1 ki, sum ~ Lkup ix codes, prod ~ Lkup n sum)
=> Constr sum n
-> NPHole ki fam ix prod
-> [DotSM NodeId]
visualizeNPHole c (H poa) =
freshNode [toLabel "*"] :
elimNP (elimNA (\k -> freshNode [toLabel (show k)]) undefined) poa
visualizeNPHole c (T a h) =
let elimK k = freshNode [toLabel (show k)]
-- we don't visualize recursion for now, clutters tree
elimI i = freshNode [toLabel "..."]
in
elimNA elimK elimI a : visualizeNPHole c h

gives the following type error:

    /home/arian/Documents/UU/Thesis/generics/generics-mrsop-diff/src/Generics/MRSOP/GraphViz/Zipper.hs:33:6: error:
         Could not deduce: Lkup ix codes0 ~ sum
          from the context: (IsNat ix, Show1 ki, sum ~ Lkup ix codes,
                             prod ~ Lkup n sum)
            bound by the type signature for:
                       visualizeNPHole :: forall kon1 (ix :: Nat) (ki :: kon1
                                                                         -> *) (sum :: [[Atom
                                                                                           kon1]]) (codes :: [[[Atom
                                                                                                                  kon1]]]) (prod :: [Atom
                                                                                                                                       kon1]) (n :: Nat) (fam :: [*]).
                                          (IsNat ix, Show1 ki, sum ~ Lkup ix codes,
                                           prod ~ Lkup n sum) =>
                                          Constr sum n -> NPHole ki fam ix prod -> [DotSM NodeId]
            at src/Generics/MRSOP/GraphViz/Zipper.hs:(33,6)-(36,19)
          sum is a rigid type variable bound by
            the type signature for:
              visualizeNPHole :: forall kon1 (ix :: Nat) (ki :: kon1
                                                                -> *) (sum :: [[Atom
                                                                                  kon1]]) (codes :: [[[Atom
                                                                                                         kon1]]]) (prod :: [Atom
                                                                                                                              kon1]) (n :: Nat) (fam :: [*]).
                                 (IsNat ix, Show1 ki, sum ~ Lkup ix codes, prod ~ Lkup n sum) =>
                                 Constr sum n -> NPHole ki fam ix prod -> [DotSM NodeId]
            at src/Generics/MRSOP/GraphViz/Zipper.hs:(33,6)-(36,19)
         In the ambiguity check for visualizeNPHole
          To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
          In the type signature:
            visualizeNPHole :: (IsNat ix,
                                Show1 ki,
                                sum ~ Lkup ix codes,
                                prod ~ Lkup n sum) =>
                               Constr sum n -> NPHole ki fam ix prod -> [DotSM NodeId]
       |
    33 |      (IsNat ix, Show1 ki, sum ~ Lkup ix codes, prod ~ Lkup n sum)
       |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
    

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.