githwxi / ATS-Postiats

ATS2: Unleashing the Potentials of Types and Templates
www.ats-lang.org
Other
354 stars 54 forks source link

function template type for cast fails #261

Closed okeuday closed 3 years ago

okeuday commented 3 years ago

An example of this problem is below:

#include "share/atspre_define.hats"
#include "share/atspre_staload.hats"
staload
UN = "prelude/SATS/unsafe.sats"

fn {s:t@ype}
print_state {l:agz}
    (state_pfgc: !s @ l |
     state_p: ptr l): void = let
    val state: int = $UN.ptr0_get<int>(state_p) // works
    val state_s: s = $UN.ptr0_get<s>(state_p) // created S2Eerrexp() !
in
    println!(state)
end

implement main0 () = let
    var state: int = 42
in
    print_state(view@state | addr@state)
end

If changed to print state_s the attempt to print will fail due to the S2Eerrexp() term. The state_s value should be able to print with the same output provided for state, right? Is this something that should work in the future?

githwxi commented 3 years ago

This is due to very limited support for overloading in ATS2. Already fixed in ATS3. The following code compiles without any issues:

fn {s:t@ype}
print_state {l:agz}
( state_pfgc : !s @ l
| state_p: ptr l     ) : void =
let
  val state_s: s = $UN.ptr0_get<s>(state_p)
in
  fprint_val<s>(stdout_ref, state_s)
end

implement
main0 () = let
  var state: int = 42
in
  print_state<int>(view@state | addr@state)
end
okeuday commented 3 years ago

Thank you for the information