Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top-level lazy functions don't typecheck #1066

Closed
mb64 opened this issue Feb 14, 2021 · 6 comments
Closed

Top-level lazy functions don't typecheck #1066

mb64 opened this issue Feb 14, 2021 · 6 comments

Comments

@mb64
Copy link
Contributor

mb64 commented Feb 14, 2021

Steps to Reproduce

Make a top-level declaration with a lazy type that can't be inferred:

foo : Inf (Unit -> Unit)
foo = \x => x

bar : Inf (Unit -> Unit)
bar = Delay (\x => x)

Expected Behavior

They should type check fine.

Observed Behavior

Error: Not a function name in pattern LHS

t.idr:2:1--2:14
   |
 2 | foo = \x => x
   | ^^^^^^^^^^^^^

Error: While processing right hand side of bar. Can't infer delay type

t.idr:5:7--5:20
   |
 5 | bar = Delay \x => x
   |       ^^^^^^^^^^^^^
@gallais
Copy link
Member

gallais commented Feb 15, 2021

Note that Lazy and Inf are not the same thing.

@mb64
Copy link
Contributor Author

mb64 commented Feb 15, 2021

That is true. In this case, changing Inf to Lazy gives exactly the same output, hence the lowercase-L "lazy" -- sorry for not making that clear.

@iacore
Copy link
Contributor

iacore commented Apr 25, 2022

Note that Lazy and Inf are not the same thing.

@gallais Can you elaborate? I was recently testing Inf but discovered that it can do the same thing as Lazy in the following code:

record Foo where
    constructor MkFoo
    bar : Lazy Foo -- could be Inf Foo
    baz : Nat


print_rec : Foo -> Nat -> IO ()
print_rec ff Z = pure ()
print_rec ff (S remaining) = do
    putStrLn (show ff.baz)
    print_rec ff.bar remaining


aa : Foo
bb : Foo
aa = MkFoo bb 1
bb = MkFoo aa 2
selfrec = MkFoo selfrec 3


main : IO ()
main =
    do
        let cc = { baz := 42 } aa
        let dd = { baz := 20 } bb
        print_rec cc 10
        print_rec dd 10
        print_rec selfrec 4

I was also confused by Delay in REPL. Sometimes Delay a show up where Lazy a should in REPL.

Main> :ti aa.bar
aa .bar : Inf Foo
Main> :ti Foo.bar
Main.Foo.bar : Foo -> Inf Foo
Main> aa
MkFoo (Delay bb) 1

# now change  Lazy Foo  to  Inf Foo

Main> :r
1/1: Building inf (inf.idr)
Loaded file inf.idr
Main> aa
MkFoo (Delay bb) 1
Main> :ti Foo.bar
Main.Foo.bar : Foo -> Lazy Foo

@ohad
Copy link
Collaborator

ohad commented Apr 25, 2023

👍 for this issue.
Does anyone know why it's happening?
Since this is potentially blocking me, I might be able to try and fix it with some assistance.

@iacore
Copy link
Contributor

iacore commented Apr 25, 2023

+1 for this issue. Does anyone know why it's happening? Since this is potentially blocking me, I might be able to try and fix it with some assistance.

Avoid this feature. Use a normal function or something.

mjustus added a commit to mjustus/Idris2 that referenced this issue Apr 25, 2023
mjustus added a commit to mjustus/Idris2 that referenced this issue Apr 25, 2023
@ohad
Copy link
Collaborator

ohad commented Apr 26, 2023

@iacore wrote:

Avoid this feature. Use a normal function or something.

I can't, see #2936

mjustus added a commit to mjustus/Idris2 that referenced this issue May 26, 2023
When we encounter a delayed (explicit) function type during elaboration
of a LHS, we strip off the delay modality, continue elaboration and return a delayed version of the resulting type.

Note: defining delayed function via pattern matching is not currently
supported. Doing so will require adding a delay marker to LHSs/contexts
familiar from modal type theories. Implicit function are also currently
not supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants