google-research / dex-lang

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

Can't unpack dependent pairs. #1131

Closed duvenaud closed 1 year ago

duvenaud commented 2 years ago

Constructing and returning a dependent pair works fine:

def transpose_ix {n} [Ix n] (i:n) (j:(i..)) : (i:n &> ..i) =
  j' = inject n j
  i' = unsafe_project _ i
  (j' ,> i')

But unpacking one from a function doesn't seem to have been added to the syntax:

def LowerTriMat (n:Type) [Ix n] (v:Type) : Type = (i:n)=>(..i)=>v
def UpperTriMat (n:Type) [Ix n] (v:Type) : Type = (i:n)=>(i..)=>v

def transpose_lower_to_upper {n v} (lower:LowerTriMat n v) : UpperTriMat n v =
  for i j.
    (j' ,> i') = transpose_upper_ix i j
    lower.j'.i'

gives

Syntax error: Illegal pattern

    (j' ,> i') = transpose_upper_ix i j
     ^^^^^^^^

Inlining the function works.