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
| open System | |
| type Option<'a> = | |
| | Some of 'a | |
| | None | |
| type Config = | |
| { Url: string | |
| Name: string | |
| Age: int } |
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
| open System | |
| type Option<'a> = | |
| | Some of 'a | |
| | None | |
| type Config = | |
| { Url: string | |
| Name: string | |
| Age: int } |
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
| 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" |
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
| open System | |
| type Option<'a> = | |
| | Some of 'a | |
| | None | |
| type Config = | |
| { Url: string | |
| Name: string | |
| Age: int } |
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
| 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) |
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
| public class Config | |
| { | |
| public Config(string url, string name, int age) | |
| { | |
| var errors = new List<string>(); | |
| if (url == null) | |
| { | |
| errors.Add("Url is null"); | |
| } | |
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
| 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 |
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
| public class ReferenceInt | |
| { | |
| public int MyInt1; | |
| public int MyInt2; | |
| public int MyInt3; | |
| public int MyInt4; | |
| } | |
| public void UseReferenceInt(ReferenceInt r) { } |
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
| public class ReferenceInt | |
| { | |
| public int MyInt; | |
| } | |
| public void UseReferenceInt(ReferenceInt r) { } | |
| public struct StructInt | |
| { | |
| public int MyInt; |
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
| // 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 () |