Created
September 26, 2014 05:33
-
-
Save tamizhvendan/268f405f64ce99b19548 to your computer and use it in GitHub Desktop.
if-your-fsharp-code-compiles-it-usually-works
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
| hasFever (Celsius 10.5) | |
| hasFever (Fahrenheit 22.5) |
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
| let hasFever temperature = | |
| match temperature with | |
| | Celsius value -> (value > 37.5) |
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
| let tempInCelsius = Celsius 10.8 | |
| let tempInFahernheit = Fahrenheit 10.6 |
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
| let hasFever temperature = | |
| match temperature with | |
| | Celsius value -> (value > 37.5) | |
| | Fahrenheit value -> (value > 99.0) |
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 abstract class Temperature | |
| { | |
| public double Value { get; private set; } | |
| protected Temperature(double value) | |
| { | |
| Value = value; | |
| } | |
| } | |
| public class Celsius : Temperature | |
| { | |
| public Celsius (double value) : base(value) | |
| { | |
| } | |
| } | |
| public class Fahrenheit : Temperature | |
| { | |
| public Fahrenheit (double value) : base(value) | |
| { | |
| } | |
| } | |
| public class Program | |
| { | |
| public static void Main() | |
| { | |
| Temperature tempInCelsius = new Celsius(10.8); | |
| Temperature tempInFahernheit = new Fahrenheit(10.6); | |
| } | |
| } |
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 Temperature = | |
| | Celsius of double | |
| | Fahrenheit of double |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment