aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser/hs/Safe.hs
diff options
context:
space:
mode:
Diffstat (limited to 'bruiser/hs/Safe.hs')
-rw-r--r--bruiser/hs/Safe.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/bruiser/hs/Safe.hs b/bruiser/hs/Safe.hs
new file mode 100644
index 0000000..8994e9e
--- /dev/null
+++ b/bruiser/hs/Safe.hs
@@ -0,0 +1,9 @@
+{-#Language ForeignFunctionInterface#-}
+module Safe where
+import Foreign.C.Types
+fibonacci :: Int -> Int
+fibonacci n = fibs !! n
+ where fibs = 0 : 1: zipWith (+) fibs (tail fibs)
+fibonacci_hs ::CInt -> CInt
+fibonacci_hs = fromIntegral.fibonacci.fromIntegral
+foreign export ccall fibonacci_hs::CInt->CInt