This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
// Copyright (c) 2012 Calvin Rien | |
// http://the.darktable.com | |
// | |
// This software is provided 'as-is', without any express or implied warranty. In | |
// no event will the authors be held liable for any damages arising from the use | |
// of this software. | |
// | |
// Permission is granted to anyone to use this software for any purpose, | |
// including commercial applications, and to alter it and redistribute it freely, | |
// subject to the following restrictions: |
Full source: https://gist.github.com/mrange/aa9e0898492b6d384dd839bc4a2f96a1
Option<_>
is great for ROP (Railway Oriented Programming) but we get no info on what went wrong (the failure value is None
which carries no info).
With the introduction F# 4.1 we got Result<_, _>
a "smarter" Option<_>
as it allows us to pass a failure value.
However, when one inspects the signature of Result.bind
one sees a potential issue for ROP:
|= dim=@ud | |
^- @ux | |
:: Pixel bytes for 24bpp dim*dim image | |
:: Note: this calculation does not support padding, so dim%4 must be 0 | |
:: | |
=/ datasize=@ (mul 3 (mul dim dim)) | |
:: The header is a list of [bytes, value] to be composed into a single blob | |
:: | |
=/ header=@ | |
%+ can 3 |
I suggest that you create one or more Api.fs
files to expose F# code in a C# friendly way.
In this file:
PascalCase
names. They will appear to C# as static methods.