Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Last active January 1, 2016 18:01
Show Gist options
  • Select an option

  • Save panesofglass/407064c47df474ef55ef to your computer and use it in GitHub Desktop.

Select an option

Save panesofglass/407064c47df474ef55ef to your computer and use it in GitHub Desktop.
Experiments with F#
// 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