Skip to content

Instantly share code, notes, and snippets.

@tamizhvendan
Created September 26, 2014 05:33
Show Gist options
  • Select an option

  • Save tamizhvendan/268f405f64ce99b19548 to your computer and use it in GitHub Desktop.

Select an option

Save tamizhvendan/268f405f64ce99b19548 to your computer and use it in GitHub Desktop.
if-your-fsharp-code-compiles-it-usually-works
hasFever (Celsius 10.5)
hasFever (Fahrenheit 22.5)
let hasFever temperature =
match temperature with
| Celsius value -> (value > 37.5)
let tempInCelsius = Celsius 10.8
let tempInFahernheit = Fahrenheit 10.6
let hasFever temperature =
match temperature with
| Celsius value -> (value > 37.5)
| Fahrenheit value -> (value > 99.0)
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);
}
}
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