{-# LANGUAGE ForeignFunctionInterface, DeriveDataTypeable #-} module MLP where import Foreign.Ptr import Foreign.C.Types import Foreign.C.String import Data.Typeable import Control.Exception data Error = NOT_SUPPORTED | NOT_IMPLEMENTED | OK | INTERNAL_ERROR | RUNTIME_ERROR | LIBRARY_ERROR deriving (Show, Eq) data ErrorException = ErrorException Error (Maybe String) deriving (Show, Eq, Typeable) instance Exception ErrorException where data Type = BOOL | LONG | DOUBLE | CHAR | STRING | OBJECT | EXCEPTION deriving (Show, Eq) newtype C_context = C_mlp_context (Ptr C_context) data Context = Context !(Ptr C_context) deriving (Show) newtype C_language = C_language (Ptr C_language) data Language = Language !(Ptr C_language) deriving (Show) newtype C_runtime = C_runtime (Ptr C_runtime) data Runtime = Runtime !(Ptr C_runtime) deriving (Show) newtype C_value = C_value (Ptr C_value) data Value = Value !(Ptr C_value) deriving (Show) newtype C_object = C_object (Ptr C_object) data Object = Object !(Ptr C_object) deriving (Show) foreign import ccall unsafe "mlp.h _mlp_debug" c_debug :: CString -> CInt -> CString -> IO () debug :: Int -> String -> IO () debug l s = do withCString "haskell" $ \name -> do withCString s $ \msg -> do c_debug name (fromIntegral l) msg withFuncDebug :: String -> IO a -> IO a withFuncDebug msg a = do MLP.debug 1 $ "-> " ++ msg ret <- a MLP.debug 1 $ "<- " ++ msg return ret