Converting Between Integer Types in WebSharper

WebSharper seems to have some difficulties converting between integer types (say, from int32 to uint64 ). I get the following:

Error: Failed to translate method call: ToUInt64 (..) [Microsoft.FSharp.Core.Operators]

The same thing happens with int32 uint32 , uint32 - int16 int32 and many others (only byteint32 ).

So the question is: how do I get around this problem? I have an integer i (which is int32 , since I cannot get anything else), and now I want to get the i -th element from Uint8Array . Uint8Array.Get wants uint64 . How to convert my i to uint64 ?

I was going to use cheat [<Inline>] , but that will not work either, because I get this error even if I try to return or pass as an argument any integer other than the int32 form.

+4
source share
1 answer

From your comments, it sounds like you're on the right track. WebSharper does not currently implement any binary processing of the .NET API, so it is proper to implement it yourself. Using numeric types for a reasonable compilation time, bearing in mind that they are all represented as Number in JavaScript, is also a good idea. If you are missing conversion proxies from the standard library, you can add them or use the Inline definition, I believe this should work:

 [<AutoOpen>] module Conversions = [<Inline "$0">] let inline int64 x = int64 x [<Inline "$0">] let inline int32 x = int32 x [<Inline "$0">] let inline uint32 x = uint32 x [<Inline "$0">] let inline uint64 x = uint64 x 

Of course, in the above implementations, the truncation that these operators do in F # / is not performed. NET

+4
source

All Articles