Created
January 14, 2015 10:40
-
-
Save Porges/202d10c76ed99c0d15cd to your computer and use it in GitHub Desktop.
This file contains 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
open System | |
open System.Runtime.InteropServices | |
open Microsoft.Win32.SafeHandles | |
// Wrapping the fact.rs module... | |
[<DllImport("fact.dll")>] | |
extern uint64 fact(uint64) | |
[<DllImport("point.dll")>] | |
extern void free_point(IntPtr) | |
// .NET will free the Point for us when we're done | |
type Point() = | |
inherit SafeHandleZeroOrMinusOneIsInvalid(true) | |
override this.ReleaseHandle() = free_point(this.handle); true | |
[<DllImport("point.dll")>] | |
extern Point mk_point(uint64, uint64) | |
[<DllImport("point.dll")>] | |
extern void add_point(Point, Point) | |
[<DllImport("point.dll")>] | |
extern void print_point(Point) | |
let mkPoint x y = mk_point (x, y) | |
// This modifies the first point in-place. | |
let addPoint x y = add_point (x, y) | |
// This prints its argument | |
let printPoint = print_point | |
// Testing the point functions; we should 'use' the | |
// point so it is freed as early as possible | |
let points () = | |
use a = mkPoint 2UL 3UL | |
use b = mkPoint 1UL 1UL | |
addPoint a b | |
printPoint a | |
[<EntryPoint>] | |
let main args = | |
printfn "fact(5) = %u" (fact 5UL) | |
points() | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment