F#: Type Test Pattern

In this video, I document my understanding of F#’s Type Test Pattern:

 

Here’s a snippet:
open System

let requestFromIO number =

try
let result = 100 / number
Some “Operation Suceeded”

with
| “:?” DivideByZeroException -> Some “DivideByZeroException”
| “:?” AccessViolationException -> Some “AccessViolationException”
| _ -> None

let result = requestFromIO 0

Here’s another snippet
open System

let reportError (error:Exception) =
match error with
| “:?” DivideByZeroException -> “DivideByZeroException”
| “:?” FieldAccessException -> “FieldAccessException”
| _ -> “IDK”

let result = reportError (FormatException())

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: