Inline type hints for polymorphic results of copy_from_string and friends
When dealing with functions that can return anything, such as
copy_from_string, it is sometimes difficult to get the types straight when the returned thing is polymorphic.
import StdEnv import dynamic_string Start = (reverse` [1..5], reverse` ['a'..'e']) where reverse_s = copy_to_string reverse (reverse`,_) = copy_from_string reverse_s
This fails with a type error, since
reverse` cannot take a
[Int] in the first element of the tuple and a
[Char] in the second element.
I then tried to make the polymorphism explicit:
cast_rev :: (A.a: [a] -> [a]) -> [a] -> [a] cast_rev f = f Start = (cast_rev reverse` [1..5], cast_rev reverse` ['a'..'e'])
But that fails as well:
Type error [type.icl,6,Start]:"argument 1 of cast_rev : reverse`" cannot unify demanded type with offered type: [E.12 ] -> [E.12 ] [E.16 ] -> [E.16 ]
Would allowing inline type hints be possible, like so:
(reverse` :: A.a: [a] -> [a],_) = copy_from_string reverse_s
(I'm not sure if it is possible/a good idea to overload this syntax for dynamics.)
Or is there a reasonable workaround?