This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Functors and modular implicits | |
* opam switch 4.02.0+modular-implicits | |
* eval `opam config env` | |
*) | |
module type FUNCTOR = sig | |
type 'a t | |
val map : ('a -> 'b) -> 'a t -> 'b t | |
end | |
let map {F : FUNCTOR} = F.map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* General functor signature. *) | |
module type FUNCTOR = sig | |
type 'a t | |
val map : ('a -> 'b) -> 'a t -> 'b t | |
end | |
(* General def of catamorphism module, parameterized by a functor *) | |
module Cata (F : FUNCTOR) = struct | |
type 'a t = 'a F.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Functor interface. | |
type Functor<'F> = { map : ('T -> 'U) -> 'F<'T> -> 'F<'U> } | |
// Monad interface. | |
type Monad<'M> = { | |
return : 'T -> 'M<'T> | |
join : 'M<'M<'T>> -> 'M<'T> | |
} | |
// Monad "library" (operations over monads). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Collections.Generic | |
// The problem I'm addressing is aggregating elements from a tree. | |
// In my particular scenario I'm interested in collecting all leaf nodes | |
// into an array. The fundamental problem is captured by the different versions | |
// of aggregate, listed below. The functions are merely simulating the branching | |
// and aggregation steps. I'm not concerned about the order of the elements. | |
// In the comments are the total times in milliseconds | |
// running the functions with n = 1e6. That is generating an array of roughly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Formlet.Do { | |
let! n = Controls.Button "Add Tabs" | |
return! | |
List.init n (fun ix -> | |
("Tab " + string ix, Controls.Input "") | |
) | |
|> Controls.TabsChoose | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createCounter = function() { | |
var x = 0; | |
return ( | |
function () { | |
x = x + 1; | |
return x; | |
} | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MyControl() = | |
inherit IntelliFactory.WebSharper.Web.Control () | |
[<JavaScript>] | |
override this.Body = | |
let inpCtrl str = | |
Controls.Input str | |
|> Enhance.WithSubmitButton | |
|> Enhance.WithFormContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[<JavaScript>] | |
let InputDate () = | |
let inputId = NewId () | |
Controls.InputDatepicker None | |
|> Formlet.MapElement (fun el -> Div [Attr.Id inputId] -< [el]) | |
|>! OnAfterRender (fun el -> | |
JQuery.JQuery.Of("#" + inputId).Find("input").Val("").Ignore | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open M | |
Foo () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Formlet.Do { | |
let! x = Controls.RadioButtonGroup None [("item1","item1");("item2","item2");("item3","item3")] | |
return x | |
} | |
|> Formlet.Map Some | |
|> Formlet.InitWith None | |
|> Enhance.WithSubmitAndResetButtons | |
|> Enhance.WithFormContainer |
NewerOlder