on master help sign in
Add nullPtr/validFile
c82f2f4Edwin Brady
lib/prelude.idr+8
@@ -240,6 +240,14 @@ feof : File -> IO Bool
240feof (FHandle h) = do eof <- do_feof h
240feof (FHandle h) = do eof <- do_feof h
241 return (not (eof == 0))
241 return (not (eof == 0))
242
242
243+nullPtr : Ptr -> IO Bool
244+nullPtr p = do ok <- mkForeign (FFun "isNull" [FPtr] FInt) p
245+ return (ok /= 0);
246+
247+validFile : File -> IO Bool
248+validFile (FHandle h) = do x <- nullPtr h
249+ return (not x)
250+
243while : |(test : IO Bool) -> |(body : IO ()) -> IO ()
251while : |(test : IO Bool) -> |(body : IO ()) -> IO ()
244while t b = do v <- t
252while t b = do v <- t
245 if v then (do { b; while t b }) else return ()
253 if v then (do { b; while t b }) else return ()