Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websharper : Using LI tags

Tags:

f#

websharper

I want to create something like that :

<ul>
    <li>menu1
         <ul>
             <li>sub-menu1</li>
         </ul>
    </li>
    <li>menu2</li>
</ul>

So i write the following code using WebSharper :

let el =
        UL [
            LI [
                Text "menu1"
                UL [
                    LI [Text "sub-menu1"]
                ]
            ]
            LI [Text "menu2"]
        ]

But it says that

UL [
    LI [Text "sub-menu1"]
]

should have the type IPagelet but currently have the type Element.

Does anyone have an idea on how to put a text + something else under an li element using WebSharper ?

Edit: Just to say that I have a bug on stakc, I can't comment or accepted the answer of @Tarmil...

like image 939
Maxime Mangel Avatar asked Sep 15 '14 14:09

Maxime Mangel


1 Answers

The issue here is that two elements in the same list, Text "menu1" and UL [...], have types IPagelet and Element respectively. Element is a subtype of IPagelet, so this should work, but unfortunately the F# type inference has some difficulties with this situation. So you need to help it by casting UL [...] to IPagelet:

let el =
    UL [
        LI [
            Text "menu1"
            UL [
                LI [Text "sub-menu1"]
            ] :> IPagelet
        ]
        LI [Text "menu2"]
    ]

In fact, this problem would be eliminated if the combinators had type seq<IPagelet> -> Element instead of seq<#IPagelet> -> Element. We will probably change them to that in the future, but since it would be a breaking change, we're keeping it for the next major version.

like image 148
Tarmil Avatar answered Sep 27 '22 18:09

Tarmil