google-research / google-research/dex-lang

The ! operator cannot handle dependent types, unlike .

Open
#239 5 comments 0 reactions 0 assignees View on GitHub
language / type system
Dominant language
Haskell
Stars
1.7k
Forks
116
PR merge metrics
No merged PRs in 30d

Description

I don't think there's currently a way to use ```%indexRef```, aka the ```!``` indexing operator for references, on diagonal types. I think the type unification search isn't flexible enough. Here's a minimal working example:

```
def lu (_:Eq n) ?=> : i:n=>(i..)=>Float =

def update (uRef:Ref _ (i:n=>(i..)=>Float)) : _ =
for j:n.
for i:(..j).
s = sum for k':(..i).
get uRef!k!j
()

init = for i j. 0.0
snd $ withState init update
```

Gives
```
Type error:Can't unify with skolem vars
Expected: (Ref c (d => b))
Actual: (Ref a ((i:n) => (i..) => Float32))
(Solving for: [a:Type, b:Type, c:Type, d:Type])

get uRef!k!j
^^^^
```
Which kind of makes sense - it would be hard to cut the triangular type in two. Even if this could be fixed, this code has other problems, which I think might best be addressed with a more flexible generalization of ```%inject```.

I played around with trying to write a fancier version of the ```!``` operator, which would do this, or perhaps one that would take two arguments, but I think I hit the limits of either the search or the error messages. For example,
```
def lowerrefindex (ref:Ref h (i':n=>(..i')=>Float)) (i:n) : Ref h ((..i')=>Float) =
%indexRef ref i
```
gives
```
Type error:
Expected: (Ref h ((..i') => Float32))
Actual: (Ref h ((..i') => Float32))
```
![Screen Shot 2020-09-19 at 10 54 31 PM](https://user-images.githubusercontent.com/2690917/93693226-183a4b00-facb-11ea-95c0-617970598de8.png)

Contributor guide

Open the contributing guide

Research direction

Start with the %indexRef and ! indexing behavior shown in the minimal example, then compare it with the attempted lowerrefindex definition and the %inject discussion. Reproduce the reported unification errors and determine whether the type-unification search or indexing generalization is the relevant entry point; done means dependent and diagonal reference indexing type-checks with clear diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.