Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Created April 2, 2014 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liammclennan/9925787 to your computer and use it in GitHub Desktop.
Save liammclennan/9925787 to your computer and use it in GitHub Desktop.
Problem using F# match
// this works
let makeImage bytes =
match Array.length bytes with
| 784 -> Image bytes |> Some
| _ -> None
// but this does not. The none branch is never used.
let makeImage bytes =
let numOfPixels = 784
match Array.length bytes with
| numOfPixels -> Image bytes |> Some
| _ -> None
@johnbfair
Copy link

Line 14 is a typo I presume. You're naming the result of Array.length bytes instead of using the value you've assigned in line 12. The only way to make that work (that i'm aware of) is:

let makeImage bytes =
    let numOfPixels = 784
    match Array.length bytes with
        | x when x = numOfPixels -> Image bytes |> Some
        | _ -> None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment