Last active
January 1, 2016 18:01
-
-
Save panesofglass/407064c47df474ef55ef to your computer and use it in GitHub Desktop.
Experiments with F#
This file contains hidden or 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
| // F# equivalent of ML signatures? | |
| type MSIG = | |
| interface | |
| // Cannot embed type signatures. | |
| //type key | |
| abstract x : int | |
| end | |
| // F# equivalent of ML structures? | |
| type M = | |
| struct | |
| // Cannot embed type signatures. | |
| //type key = string | |
| val x : int | |
| private new(value) = { x = value } | |
| interface MSIG with | |
| member this.x = this.x | |
| static member instance = M(1) | |
| end | |
| printfn "M.instance.x = %A" M.instance.x | |
| // Another attempt using a class hardly helps | |
| type M' private () = | |
| class | |
| static let x = 1 | |
| static member instance = M'() | |
| interface MSIG with | |
| member this.x = x | |
| end | |
| // Essentially, modules and their .fsi signature files | |
| // make up F#'s support for signatures and structures, | |
| // where modules are non-parameterized structures. | |
| module M'' = | |
| let x = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment