tag:blogger.com,1999:blog-2744072865491516720.post1441982466138693174..comments2023-05-03T06:35:33.259-04:00Comments on Higher Logics: Idioms in C# with LINQSandro Magihttp://www.blogger.com/profile/05446177882449578817noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-2744072865491516720.post-29178547048109709492011-09-26T00:15:54.426-04:002011-09-26T00:15:54.426-04:00Re: desktop formlets, it's certainly possible,...Re: desktop formlets, it's certainly possible, you just have to define an abstract set of portable UI controls, and define a mapping to HTML+CSS. Formlets are generally only used in web apps because the structure of a web program is so much more difficult than the desktop where you don't have to handle partial failure, latency, disconnected operation, backtracking, etc.<br /><br />Try thinking how you'd design a distributed GUI framework with all the properties we get from HTTP+HTML. You can have stateful designs like X11, or stateless designs like HTTP. If you go stateless, something like formlets is a natural development I think. A stateless GUI framework that can map to HTTP is strictly more general than a purely desktop framework.<br /><br />Re: bidirectional data binding, you have it exactly right. The UI is a data structure defined in terms of the data model, and the data model itself is defined in terms of the UI. Updates to one should be reflected in the other and vv, data flow in either direction should be a well-defined operation. This well-defined mutually recursive relationship is exactly a lens.<br /><br />Two possible approaches here again: a functional one, of which formlets is one design; the other is to take the imperative route based on events and reactive expressions, which is what I'm trying: use .NET events and IObservables to keep data model and UI in sync without any manual intervention aside from the initial data binding code.<br /><br />So yes, lenses would be useful on .NET, and we're both trying to achieve it by the sounds of it. A lot of the convenience you get from .NET, with its easy integration between data grids, SQL sources, etc. could be done much more simply if they had a universal framework for bidirectional data binding, instead of all this custom code for a thousand APIs.Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-26500589417969537412011-09-25T22:54:13.308-04:002011-09-25T22:54:13.308-04:00Well, technically, you can implement an applicativ...Well, technically, you can implement an applicative and monad, but of course using Join for applicative and SelectMany for the monad. Still, I'm considering using a separate type for validation (different from Either) just to keep things cleaner.<br /><br />CsFormlets is a web formlets library, so if you were looking to use it in desktop apps, this is not it :) . IIRC the concept of formlets has been applied to console and desktop apps in a generic way but I doubt this is viable in .net, plus formlets seem to be only widely used for web applications (in Haskell, Racket, etc)<br /><br />Formlets are in a way bidirectional (not sure in the same way you mean it): a single formlet is used to both project data to the UI and then collect input from the UI.<br />For a more general bidirectional tool, lenses are interesting: composable and purely functional... still trying to see if they would be truly useful in .net though.Mauricio Schefferhttps://www.blogger.com/profile/15247972578064164206noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-42840458368165459122011-09-25T18:59:05.087-04:002011-09-25T18:59:05.087-04:00Yes, I expect you can't simultaneously impleme...Yes, I expect you can't simultaneously implement an idiom and monad interface for the same type. You'd have to implement two types and convert between them. You can do this cheaply enough with a struct wrapper around one, or perhaps by implementing LINQ an interface and then doing some explicit coercions.<br /><br />Are you using CsFormlets for anything in particular? I'm developing my own portable UI library, so I'm curious what else is out there.<br /><br />I'm taking the route of bidirectional data binding instead of the purely functional formlets approach. It seems to fit better with the imperative C# model that you'd find, for instance, with LINQ to SQL. You can see what I've committed publicly under <a href="http://sasa.hg.sourceforge.net/hgweb/sasa/sasa/file/c3821ad83256/Sasa.Reactive" rel="nofollow">Sasa.Reactive</a>, but I have a lot more that I'm still playing with behind the scenes.<br /><br />Finding a good balance that works with C#'s limitations is tough though.Sandro Magihttps://www.blogger.com/profile/05446177882449578817noreply@blogger.comtag:blogger.com,1999:blog-2744072865491516720.post-57830364936063244942011-09-25T14:58:39.483-04:002011-09-25T14:58:39.483-04:00Nice! Thanks for this, I somehow suspected this wa...Nice! Thanks for this, I somehow suspected this was possible but never really checked it. I just <a href="https://github.com/mausch/CsFormlets/commit/9b64dd4be123a39f363b764a732221f7a27007f1" rel="nofollow">applied it in CsFormlets</a><br /><br />Another downside is that you can't use it if you already have a proper SelectMany (i.e. a monadic bind), as for example in the case of Either/Validation (see <a href="https://github.com/fsharp/fsharpx/blob/master/tests/FSharpx.CSharpTests/ValidationTests.cs" rel="nofollow">FSharpx</a>)Mauricio Schefferhttps://www.blogger.com/profile/15247972578064164206noreply@blogger.com