google-research / dex-lang

Research language for array processing in the Haskell/ML family
BSD 3-Clause "New" or "Revised" License
1.56k stars 106 forks source link

compiler bug: shouldn't have dict holes past inference #1268

Closed darrenjw closed 1 year ago

darrenjw commented 1 year ago

I'm hitting a compiler bug that I'm struggling to get past. I may be doing something wrong, in which case pointers would be appreciated. Minimal example below.

struct PImage(r, c, a) =
  row: r
  col: c
  im: r=>c=>a

def blank_pim(rows: Nat, cols: Nat) -> PImage(Fin rows, Fin cols, Float) =
  bi = for i:(Fin rows). for j:(Fin cols). 0.0
  PImage.new(0@(Fin rows), 0@(Fin cols), bi)

blank_pim(2, 3)

blank_pim(3, 4)

init = blank_pim(2, 3)

init
dougalm commented 1 year ago

Thanks for the bug report. I think I know what the problem is and I'll add the fix to my current patch (#1261). In the meantime, you can write this instead:

struct PImage(r|Ix, c|Ix, a) =
  row: r
  col: c
  im: r=>c=>a

But the compiler should have told you that.

Also, a heads up: when #1261 lands you'll just write PImage(0@(Fin rows), 0@(Fin cols), bi) instead of PImage.new(0@(Fin rows), 0@(Fin cols), bi)

darrenjw commented 1 year ago

That fixes my (current) problem - many thanks for your prompt response!