Git Product home page Git Product logo

Comments (3)

edwinb avatar edwinb commented on May 22, 2024

This turns out to have been a mysterious scoping bug which only arose when type checking things with lambdas in their type that happened to have the same name as something whose scope had previously been resolved. Now fixed.

from idris-dev.

nicolabotta avatar nicolabotta commented on May 22, 2024

I am afraid this could be an instance of the same problem, though in a slightly more involved situation. The following code type checks

> module TestBound

> soFalseElim : so False -> a
> soFalseElim x = FalseElim (believe_me x)

> X : Set
> X = (n : Nat ** so (n < 3))

> (==) : X -> X -> Bool
> (==) x x' = (getWitness x == getWitness x')

> data Move = L | R 

> adm : X -> Move -> Bool
> adm (n ** _) L = n <= 1
> adm (n ** _) R = n >= 1

> Y : X -> Set
> Y x = (a : Move ** so (adm x a))

> step : (x : X) -> Y x -> X
> step (O ** _) (L ** _) = (2 ** oh)
> step ((S n) ** _) (L ** _) = (n ** believe_me oh) -- trivial
> step (n ** _) (R ** _) = 
>   if n == 2 then (O ** oh) else (S n ** believe_me oh)

> pred : X -> X -> Bool
> pred x x' = (adm x L && x' == step x (L ** believe_me oh)) ||
>             (adm x R && x' == step x (R ** believe_me oh))

> succs : X -> (n : Nat ** Vect X n)
> succs x = filter (pred x) [(0 ** oh),(1 ** oh),(2 ** oh)]

> preds : X -> (n : Nat ** Vect X n)
> preds x' = filter ((flip pred) x') [(0 ** oh),(1 ** oh),(2 ** oh)]

> emptyC : (n : Nat ** Vect X n) -> Bool
> emptyC (_ ** Nil) = True
> emptyC (_ ** (x :: xs)) = False

> inC : X -> (n : Nat ** Vect X n) -> Bool
> inC _ (_ ** Nil) = False
> inC x (_ ** (x' :: xs')) = x == x' || inC x (_ ** xs')

> someC : (X -> Bool) -> (n : Nat ** Vect X n) -> Bool
> someC _ (_ ** Nil) = False
> someC p (_ ** (x :: xs)) = p x || someC p (_ ** xs)

> lemmaC2 : (xs : (n : Nat ** Vect X n)) ->
>           so (not (emptyC xs)) ->
>           (x : X ** so (x `inC` xs))
> lemmaC2 (_ ** Nil) soF = soFalseElim soF
> lemmaC2 (_ ** (x :: xs)) _ = (x ** believe_me oh)

> lemmaC3 : (x : X) ->
>           (p : X -> Bool) ->
>           (xs : (n : Nat ** Vect X n)) ->
>           so (p x) ->
>           so (inC x xs) ->
>           so (someC p xs)
> lemmaC3 _ _ (_ ** Nil) _ soF = soFalseElim soF
> lemmaC3 _ _ (_ ** (x :: xs)) _ _ = ?lemmaC3_2

> succsTh : (x : X) -> so (not (emptyC (succs x)))
> succsTh x = ?lala

> reachable : (m : Nat) -> X -> Bool
> reachable O _ = True
> reachable (S m) x' = someC (reachable m) (preds x')

> viable : (n : Nat) -> X -> Bool
> viable O _ = True
> viable (S n) x = someC (viable n) (succs x)

> viableTh : (n : Nat) -> (x : X) -> so (viable n x)
> viableTh O _ = oh
> viableTh (S n) k = step2 where  
>   step0 : so (not (emptyC (succs k)))
>   step0 = succsTh k
>   step1 : (x' : X ** so (x' `inC` (succs k)))
>   step1 = lemmaC2 (succs k) step0
>   step2 : so (someC (viable n) (succs k))
>   step2 = lemmaC3 x' (viable n) (succs k) vnx' x'inCsuccsx where
>     x' : X
>     x' = getWitness step1
>     vnx' : so (viable n x')
>     vnx' = viableTh n x' -- induction step
>     x'inCsuccsx : so (x' `inC` (succs k))
>     x'inCsuccsx = getProof step1

But replacing |k| with |x| in the second pattern of the definition of |viableTh| yields

test_bound.lidr:81:Can't unify (x' ** so (inC x' ...)) with (x ** so (inC x ...))

Maybe re-open the issue ?

from idris-dev.

nicolabotta avatar nicolabotta commented on May 22, 2024

There was a rendering error in the above message (I used |pre| instead of |````| to mark code) which made the code unusable. It should type check, now.

from idris-dev.

Related Issues (20)

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.