Skip to content

Instantly share code, notes, and snippets.

@mr5z
Last active January 28, 2020 01:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mr5z/b37dbc557d7c6b243c169f8ae60d8d4b to your computer and use it in GitHub Desktop.
Save mr5z/b37dbc557d7c6b243c169f8ae60d8d4b to your computer and use it in GitHub Desktop.
M#
package com.msharp.Test
use System.Types
use System.Math
// Defining a constants
config A = 0
config B = 0
config LocalConfig { // enum
A = 0
B = 1
C = "hello",
D = new LocalConfig() // Error
E = new Object() // Ok
}
// Defining a class
model User {
:constructors // Regioning + Public Accessibility (cannot declare anything other than public constructors)
ctor() {
isAlive = true
}
ctor(isAlive: bool) {
self.isAlive = isAlive
}
ctor(firstName: string?, lastName: string?) {
FirstName = firstName
LastName = lastName
isAlive = firstName!.HashCode % 2 eq 0
local a = true and false
local b = false or true
local c = a not eq b
}
:configuration: // Regioning + Public Accessibility (cannot declare anything other than private constants)
config KeyForCache = "KeyForCache"
config MaxAbsent = 25
config MaxTemperatureInCelsius = 38.3
:properties // Regioning + Public Accessibility (cannot declare anything other than public properties)
FirstName: string?
LastName: string?
:behaviors // Regioning + Public Accessibility (cannot declare anything other than public methods)
Eat() -> void {
Console.Log("Eating...")
}
:fields // Regioning + Private Accessibility (cannot declare anything other than private variables)
isAlive -> readonly bool // triggers compile error when no initialization from ctor
isBusy -> bool
secret -> string?
}
specification IDisposable {
Dispose() -> void
}
abstract Human: IDisposable {
:constructors.derivative
ctor(firstName: string) {
FirstName = firstName
}
:properties.derivative
FirstName: string
:behaviors
Eat() -> void {
Console.Log("Eating...")
}
:specifications.derivate
Dispose() {
}
}
// Test
main() -> int {
local user: new User {
FirstName: "Lupin"
LastName: "TheThird"
}
user.Eat()
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment