zfnmxt / diving-beet

A port of Falling Turnip from Haskell to Futhark and Python :boom:
GNU General Public License v3.0
0 stars 0 forks source link

Type mismatch between Python tuple and opaque Futhark tuple. #1

Open zfnmxt opened 5 years ago

zfnmxt commented 5 years ago

In world.fut:

type element_type = #nothing | #steam_water | ...
type element = (element_type, u8)

make run then generates the following error:

python diving-beet.py
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Using futhark-pyopencl backend.
Choose platform:
[0] <pyopencl.Platform 'NVIDIA CUDA' at 0x563b623e6620>
Choice [0]:Set the environment variable PYOPENCL_CTX='0' to avoid being asked again.
Traceback (most recent call last):
  File "diving-beet.py", line 95, in <module>
    pointing_at_name = element_name(now_pointing_at)
  File "diving-beet.py", line 50, in element_name
    return ''.join(map(chr,list(beet.element_name(elem))))
  File "/home/zfnmxt/repos/diving-beet/game.py", line 18902, in element_name
    element_77622_ext))
TypeError: Argument #0 has invalid value
Futhark type: element
Argument has Python type <class 'tuple'> and value: (<opaque Futhark value of type #nothing | #steam_water | #steam_condensed | #oil | #water | #salt_water | 
#sand | #salt | #stone | #fire | #torch | #plant | #spout | #metal | #lava | 
#turnip | #wall | #napalm>, 0)

make: *** [Makefile:6: run] Error 1
athas commented 5 years ago

It expects something of type 'element' and you are giving it a tuple. There's not really any subtle reason why that's wrong, it just is. Looking at diving-beet.py, the element_name function is being called with the return value of element_at, which is not annotated to return an element, so it will expose the underlying type definition (which is (element_type, u8)).

This whole business with how type abbreviations affect entry points is quite subtle (I tried writing about it here), but it is also not your problem. Just add full type annotations to all entry points and all will be well.