Skip to content

Instantly share code, notes, and snippets.

View rexcfnghk's full-sized avatar

Rex Ng rexcfnghk

View GitHub Profile
open System
type Option<'a> =
| Some of 'a
| None
type Config =
{ Url: string
Name: string
Age: int }
open System
type Option<'a> =
| Some of 'a
| None
type Config =
{ Url: string
Name: string
Age: int }
type Result<'TSuccess, 'TError> =
| Ok of 'TSuccess
| Error of 'TError
// makeConfig : (url: string) -> (name: string) -> (age: int) -> Result<Config, string>
let makeConfig (url: string) (name: string) (age: int) =
if isNull name
then Error "Name is null"
elif age < 18
then Error "Age is smaller than 18"
open System
type Option<'a> =
| Some of 'a
| None
type Config =
{ Url: string
Name: string
Age: int }
public class Config
{
private Config(string url, string name, int age)
{
Url = url;
Name = name;
Age = age;
}
public static Config MakeConfig(string url, string name, int age)
public class Config
{
public Config(string url, string name, int age)
{
var errors = new List<string>();
if (url == null)
{
errors.Add("Url is null");
}
public class Config
{
public Config(string url, string name, int age)
{
if (url == null)
{
throw new ArgumentNullException(nameof(url));
}
// Adapted from https://stackoverflow.com/a/7581824/465056
public class ReferenceInt
{
public int MyInt1;
public int MyInt2;
public int MyInt3;
public int MyInt4;
}
public void UseReferenceInt(ReferenceInt r) { }
public class ReferenceInt
{
public int MyInt;
}
public void UseReferenceInt(ReferenceInt r) { }
public struct StructInt
{
public int MyInt;
// forever :: (unit -> unit) -> unit
let rec forever f =
f ()
ignore <| forever f
// Tail-recursive version
// forever' :: (unit -> unit) -> unit
let forever' =
let rec inner f =
f ()