module Language.Lean.Internal.Inductive
( InductiveType
, InductiveTypePtr
, OutInductiveTypePtr
, withInductiveType
, ListInductiveType
, ListInductiveTypePtr
, OutListInductiveTypePtr
, withListInductiveType
, InductiveDecl
, InductiveDeclPtr
, OutInductiveDeclPtr
, withInductiveDecl
) where
import Control.Lens (toListOf)
import Foreign
import Foreign.C
import Language.Lean.List
import System.IO.Unsafe
import Language.Lean.Internal.Exception
import Language.Lean.Internal.Exception.Unsafe
newtype InductiveType = InductiveType (ForeignPtr InductiveType)
withInductiveType :: InductiveType -> (Ptr InductiveType -> IO a) -> IO a
withInductiveType (InductiveType o) = withForeignPtr $! o
type InductiveTypePtr = Ptr (InductiveType)
type OutInductiveTypePtr = Ptr (InductiveTypePtr)
instance IsLeanValue InductiveType (Ptr InductiveType) where
mkLeanValue = fmap InductiveType . newForeignPtr lean_inductive_type_del_ptr
foreign import ccall unsafe "&lean_inductive_type_del"
lean_inductive_type_del_ptr :: FunPtr (InductiveTypePtr -> IO ())
newtype instance List InductiveType = ListInductiveType (ForeignPtr (List InductiveType))
type ListInductiveTypePtr = Ptr (ListInductiveType)
type OutListInductiveTypePtr = Ptr (ListInductiveTypePtr)
type ListInductiveType = List InductiveType
withListInductiveType :: List InductiveType -> (Ptr (List InductiveType) -> IO a) -> IO a
withListInductiveType (ListInductiveType p) = withForeignPtr $! p
instance IsLeanValue (List InductiveType) (Ptr (List InductiveType)) where
mkLeanValue = fmap ListInductiveType . newForeignPtr lean_list_inductive_type_del_ptr
foreign import ccall unsafe "&lean_list_inductive_type_del"
lean_list_inductive_type_del_ptr :: FunPtr (ListInductiveTypePtr -> IO ())
instance Eq (List InductiveType) where
(==) = lean_list_inductive_type_eq
lean_list_inductive_type_eq :: (ListInductiveType) -> (ListInductiveType) -> (Bool)
lean_list_inductive_type_eq a1 a2 =
unsafePerformIO $
(withListInductiveType) a1 $ \a1' ->
(withListInductiveType) a2 $ \a2' ->
let {res = lean_list_inductive_type_eq'_ a1' a2'} in
let {res' = toBool res} in
return (res')
instance IsListIso (List InductiveType) where
nil = tryGetLeanValue $ lean_list_inductive_type_mk_nil
h <| r = tryGetLeanValue $ lean_list_inductive_type_mk_cons h r
listView l =
if lean_list_inductive_type_is_cons l then
tryGetLeanValue (lean_list_inductive_type_head l)
:< tryGetLeanValue (lean_list_inductive_type_tail l)
else
Nil
lean_list_inductive_type_mk_nil :: (OutListInductiveTypePtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_list_inductive_type_mk_nil a1 a2 =
let {a1' = id a1} in
let {a2' = id a2} in
lean_list_inductive_type_mk_nil'_ a1' a2' >>= \res ->
let {res' = toBool res} in
return (res')
lean_list_inductive_type_mk_cons :: (InductiveType) -> (ListInductiveType) -> (OutListInductiveTypePtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_list_inductive_type_mk_cons a1 a2 a3 a4 =
(withInductiveType) a1 $ \a1' ->
(withListInductiveType) a2 $ \a2' ->
let {a3' = id a3} in
let {a4' = id a4} in
lean_list_inductive_type_mk_cons'_ a1' a2' a3' a4' >>= \res ->
let {res' = toBool res} in
return (res')
lean_list_inductive_type_is_cons :: (ListInductiveType) -> (Bool)
lean_list_inductive_type_is_cons a1 =
unsafePerformIO $
(withListInductiveType) a1 $ \a1' ->
let {res = lean_list_inductive_type_is_cons'_ a1'} in
let {res' = toBool res} in
return (res')
lean_list_inductive_type_head :: (ListInductiveType) -> (OutInductiveTypePtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_list_inductive_type_head a1 a2 a3 =
(withListInductiveType) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_list_inductive_type_head'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
lean_list_inductive_type_tail :: (ListInductiveType) -> (OutListInductiveTypePtr) -> (OutExceptionPtr) -> IO ((Bool))
lean_list_inductive_type_tail a1 a2 a3 =
(withListInductiveType) a1 $ \a1' ->
let {a2' = id a2} in
let {a3' = id a3} in
lean_list_inductive_type_tail'_ a1' a2' a3' >>= \res ->
let {res' = toBool res} in
return (res')
instance IsList (List InductiveType) where
type Item (List InductiveType) = InductiveType
fromList = fromListDefault
toList = toListOf traverseList
newtype InductiveDecl = InductiveDecl (ForeignPtr InductiveDecl)
withInductiveDecl :: InductiveDecl -> (Ptr InductiveDecl -> IO a) -> IO a
withInductiveDecl (InductiveDecl o) = withForeignPtr $! o
type InductiveDeclPtr = Ptr (InductiveDecl)
type OutInductiveDeclPtr = Ptr (InductiveDeclPtr)
instance IsLeanValue InductiveDecl (Ptr InductiveDecl) where
mkLeanValue = fmap InductiveDecl . newForeignPtr lean_inductive_decl_del_ptr
foreign import ccall unsafe "&lean_inductive_decl_del"
lean_inductive_decl_del_ptr :: FunPtr (InductiveDeclPtr -> IO ())
foreign import ccall unsafe "Language/Lean/Internal/Inductive.chs.h lean_list_inductive_type_eq"
lean_list_inductive_type_eq'_ :: ((ListInductiveTypePtr) -> ((ListInductiveTypePtr) -> CInt))
foreign import ccall unsafe "Language/Lean/Internal/Inductive.chs.h lean_list_inductive_type_mk_nil"
lean_list_inductive_type_mk_nil'_ :: ((OutListInductiveTypePtr) -> ((OutExceptionPtr) -> (IO CInt)))
foreign import ccall unsafe "Language/Lean/Internal/Inductive.chs.h lean_list_inductive_type_mk_cons"
lean_list_inductive_type_mk_cons'_ :: ((InductiveTypePtr) -> ((ListInductiveTypePtr) -> ((OutListInductiveTypePtr) -> ((OutExceptionPtr) -> (IO CInt)))))
foreign import ccall unsafe "Language/Lean/Internal/Inductive.chs.h lean_list_inductive_type_is_cons"
lean_list_inductive_type_is_cons'_ :: ((ListInductiveTypePtr) -> CInt)
foreign import ccall unsafe "Language/Lean/Internal/Inductive.chs.h lean_list_inductive_type_head"
lean_list_inductive_type_head'_ :: ((ListInductiveTypePtr) -> ((OutInductiveTypePtr) -> ((OutExceptionPtr) -> (IO CInt))))
foreign import ccall unsafe "Language/Lean/Internal/Inductive.chs.h lean_list_inductive_type_tail"
lean_list_inductive_type_tail'_ :: ((ListInductiveTypePtr) -> ((OutListInductiveTypePtr) -> ((OutExceptionPtr) -> (IO CInt))))