Discriminated unions, but then you have to tag every use.

type Stuff = | S of string | I of int | F of Fnord
...
f.DoSomething [ S "ok"; I 3; F f ]

Also, assuming you're talking about

[link:cs.hubfs.net]

there's also the issue that e.g. "h?tr" being assigned into h?table will surely have type "obj" anyway.

So offhand I don't see great ideas for making that all work at compile-time, unless the set fo Stuff is truly finite/limited, in which case the DU strategy may work (and "dynamic" (?) may not be needed).

By on 3/8/2010 2:26 PM ()

Discriminated unions, but then you have to tag every use.

type Stuff = | S of string | I of int | F of Fnord
...
f.DoSomething [ S "ok"; I 3; F f ]

Also, assuming you're talking about

[link:cs.hubfs.net]

there's also the issue that e.g. "h?tr" being assigned into h?table will surely have type "obj" anyway.

So offhand I don't see great ideas for making that all work at compile-time, unless the set fo Stuff is truly finite/limited, in which case the DU strategy may work (and "dynamic" (?) may not be needed).

Yes, thinking about other things to add to [link:cs.hubfs.net].

This would definitely work, but I think the extra bits that you have to put in to wrap each element just aren't worth it for compile-time errors. I'm looking for something as sparse as possible (and as close to raw HTML as possible) and adding the DU decorations would just get in the way.

And the benefit of putting in the DU here would be tiny since there's no validating the tags (there's nothing to validate against, since I want to be able to emit anything as a tag). I don't think the extra syntax would prevent any real-world bugs.

By on 3/8/2010 10:11 PM ()

That is my initial feeling too.

type Node = | T of Attribute*[Node] | TR of Attribute*[Node] | TD of ...

Though if I see such a definition, I would want it to be able to verified against a schema(hopefully at compile time) meaning defining the whole HTML schema(in this case) as F# types. Not sure if the gain worth the effort.

By on 3/8/2010 3:13 PM ()
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