{-# LINE 1 "src/Clib.hsc" #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Clib where
import BCG
import ParseBCG
import Foreign.C.String
import Foreign.C.Types
howMono :: CString -> IO CDouble
howMono :: CString -> IO CDouble
howMono CString
cStr = do
String
str <- CString -> IO String
peekCString CString
cStr
case String -> Either (ParseException, Int) BCG
parse String
str of
Right BCG
g -> CDouble -> IO CDouble
forall (m :: * -> *) a. Monad m => a -> m a
return (CDouble -> IO CDouble) -> CDouble -> IO CDouble
forall a b. (a -> b) -> a -> b
$ Double -> CDouble
CDouble (Double -> CDouble) -> Double -> CDouble
forall a b. (a -> b) -> a -> b
$ BCG -> Double
dist BCG
g
Left (ParseException, Int)
_ -> CDouble -> IO CDouble
forall (m :: * -> *) a. Monad m => a -> m a
return (CDouble -> IO CDouble) -> CDouble -> IO CDouble
forall a b. (a -> b) -> a -> b
$ Double -> CDouble
CDouble (-Double
1)
foreign export ccall howMono :: CString -> IO CDouble
foreign export ccall "how_mono" howMono :: CString -> IO CDouble