lorepozo / list-routines

Interactive dataset for program learning.
https://lucasem.github.io/list-routines/
MIT License
2 stars 0 forks source link

generate-examples crashes for some routines (but not others) #2

Closed joshrule closed 5 years ago

joshrule commented 5 years ago

For very simple routines, ./lr_cli appears to work just fine:

$ ./lr_cli generate-examples "((tail (dyn . 0)))" | jq -r '.[] | "i:\(.i) o:\(.o)"' | column -t
i:[7,6,2]              o:[6,2]
i:[8,13,14,1,12]       o:[13,14,1,12]
i:[5,1,16,1,7,8]       o:[1,16,1,7,8]
i:[12,16,2,9]          o:[16,2,9]
i:[0]                  o:[]
i:[12,13,3,5,2,12]     o:[13,3,5,2,12]
i:[14,4,6]             o:[4,6]
i:[15,13]              o:[13]
i:[10,14,6,14,5,0,10]  o:[14,6,14,5,0,10]
i:[6,10,4,5]           o:[10,4,5]

But, even simple modifications tend to fail:

$ ./lr_cli generate-examples "((tail (dyn . 0)) (head (dyn . 1)))" | jq -r '.[] | "i:\(.i) o:\(.o)"' | column -t
map: contract violation
  expected: list?
  given: #f
  context...:
   /Applications/Racket v7.3/collects/racket/private/map.rkt:180:2: check-args
   /Applications/Racket v7.3/collects/racket/private/map.rkt:257:2: gen-map
   /Applications/Racket v7.3/collects/racket/cmdline.rkt:191:51
   '#%mzc:main_cli: [running body]
   temp37_0
   for-loop
   run-module-instance!125
   perform-require!78
   top-level: [running body]
   eval-one-top12
   loop
   [repeats 1 more time]

Any ideas as to what's happening here?

lorepozo commented 5 years ago

Yeah, this is because the program you gave isn’t well typed (yikes that error message could use improvement). The type of the routine input is based on its first usage in a subroutine, it doesn’t propagate dependent type constraints backwards. In this case, tail takes an int-list with length at least 1 and its return type is a list with length one fewer than the input. Hence generated inputs will be lists of length at least one. However, head has the same constraint on its input, but that means we need a list with length two for the program to type.

Maybe you could try adding a subroutine to serve as a precondition, like take-list-length-at-least-two → tail → head. Could also try getting the type constraints to flow back up the subroutines, but I think that’s difficult

joshrule commented 5 years ago

Thanks—now I know!