Hi Paul,

I have reported the problem here:

[link:bitbucket.org]

Briefly, WebSharper uses F# quotations to perform the translation. In general, the constructor quotations produced by F# are not always correct. We perform some ad-hoc correction logic in WebSharper to try to restore their original meaning in some simple cases, but do not guarantee to be correct in general. Specifically, your example translates incorrectly.

I have reviewed the "correction" code and found a way to improve it so that your example will actually work as written. It involves shifting the Runtime.New call up the code, so that it replaces r={}. The change seems harmless with respect to other code, and we will be including this as a fix for your issue in the upcoming WebSharper release.

In the meanwhile, you can consider several workarounds, for example:

1
2
3
4
5
6
7
8
9
10
    type Canvas2 [<JavaScript>] (width, height, cellSide, canvasXOffset, canvasYOffset) =

        [<JavaScript>]
        let () =
            let element = HTML5.Tags.Canvas [] 
            let canvas = element.Dom
            let drawLife () =
                JavaScript.Log("OKAY", canvas, width, height)
            canvas?width <- width
            drawLife ()

Concerning the error "Quotations cannot contain inline assembly code or pattern matching on arrays", this is another limitation of F# quotation model for which we have no cure. It usually involves array code and can be worked around by dealing with arrays as sequences. If you post some code that generates this error I can try to help you convert it.

Thanks,
Anton.

By on 10/22/2012 9:30 AM ()

Thanks for the help; sorry for the delay in responding. The code that gives the "Quotations cannot contain inline assembly code" when I call a member from the constructor is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
type Canvas [<JavaScript>] (width, height, cellSide, canvasXOffset, canvasYOffset) as this =
    [<JavaScript>]
    let element = HTML5.Tags.Canvas []
 
    [<JavaScript>]
    let canvas  = As<CanvasElement> element.Dom
 
    do
        canvas.Width  <- width
        this.drawLife !currentState

    [<JavaScript>]
    member this.drawLife (gameState: Set<int*int>) =
        gameState |> ignore

This gives me the abovementioned error as a little red squiggly in Visual Studio under

1
gameState |> ignore

I don't even need to use the WebSharper compiler. (Naturally, the actual code was doing something a lot more involved in drawLife, but I got the same error.)

By on 10/30/2012 12:58 PM ()

This is indeed a bug, and was filed as such by Anton (a.k.a. toyvo): [link:bitbucket.org]

By on 10/22/2012 9:28 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper