Browse files

Don't export catch and Prelude

  • Loading branch information...
1 parent d3c939f commit 92d513e2ec6e9eb78e588a711ccbbdf890c3aa37 @kaoskorobase committed Dec 20, 2012
Showing with 10 additions and 23 deletions.
  1. +2 −4 Sound/File/Sndfile.hs
  2. +3 −5 Sound/File/Sndfile/Buffer.hs
  3. +3 −12 Sound/File/Sndfile/Exception.hs
  4. +2 −2 Sound/File/Sndfile/Interface.chs
View
6 Sound/File/Sndfile.hs
@@ -26,14 +26,12 @@ module Sound.File.Sndfile
, hGetContents, readFile
, hPutBuffer, writeFile
-- *Exception handling
- , Exception(..), catch
+ , Exception(..)
-- *Header string field access
, StringType(..), getString, setString
-
- , module Prelude
) where
-import Prelude hiding (catch, readFile, writeFile)
+import Prelude hiding (readFile, writeFile)
import Sound.File.Sndfile.Buffer
import Sound.File.Sndfile.Exception
import Sound.File.Sndfile.Interface
View
8 Sound/File/Sndfile/Buffer.hs
@@ -14,7 +14,6 @@ import Control.Exception (bracket)
import Control.Monad
import Foreign
import Prelude hiding (readFile, writeFile)
-import Sound.File.Sndfile.Exception (throw)
import Sound.File.Sndfile.Interface
import Sound.File.Sndfile.Buffer.Sample (Sample(..))
@@ -58,10 +57,9 @@ hPutBuffer :: forall a e . (Sample e, Storable e, Buffer a e) => Handle -> a e -
hPutBuffer h buffer = do
(fp, i, n) <- toForeignPtr buffer
if n `mod` numChannels /= 0
- then throw 0 "hPutBuffer: invalid buffer size (not a multiple of channel count)"
- else
- withForeignPtr fp $ \ptr ->
- hPutBuf h (ptr `advancePtr` i) (n `div` numChannels)
+ then error "hPutBuffer: invalid buffer size (not a multiple of channel count)"
+ else withForeignPtr fp $ \ptr ->
+ hPutBuf h (ptr `advancePtr` i) (n `div` numChannels)
where
numChannels = channels $ hInfo h
View
15 Sound/File/Sndfile/Exception.hs
@@ -1,10 +1,9 @@
{-# LANGUAGE DeriveDataTypeable #-}
module Sound.File.Sndfile.Exception (
- Exception(..),
- catch, try, throw
+ Exception(..)
+, fromErrorCode
) where
-import Control.Exception (catch, try)
import qualified Control.Exception as E
import Data.Typeable (Typeable)
import Prelude hiding (catch)
@@ -22,18 +21,10 @@ data Exception =
instance E.Exception (Exception)
--- | Construct 'Exception' from error code and string.
+-- | Construct 'Exception' from error code and message.
fromErrorCode :: Int -> String -> Exception
fromErrorCode 1 = UnrecognisedFormat
fromErrorCode 2 = SystemError
fromErrorCode 3 = MalformedFile
fromErrorCode 4 = UnsupportedEncoding
fromErrorCode _ = Exception
-
--- |Catch values of type 'Exception'.
--- catch :: IO a -> (Exception -> IO a) -> IO a
--- catch = E.catch
-
--- | Throw 'Exception' according to error code and string
-throw :: Int -> String -> a
-throw code str = E.throw (fromErrorCode code str)
View
4 Sound/File/Sndfile/Interface.chs
@@ -1,10 +1,10 @@
{-# LANGUAGE ForeignFunctionInterface #-}
module Sound.File.Sndfile.Interface where
+import qualified Control.Exception as E
import Control.Monad (liftM, when)
import Foreign
import Foreign.C
-
import qualified Sound.File.Sndfile.Exception as E
#include <stdint.h>
@@ -229,7 +229,7 @@ checkHandle :: HandlePtr -> IO ()
checkHandle handle = do
code <- liftM fromIntegral $ {#call unsafe sf_error#} handle
when (code /= 0) $
- peekCString ({#call pure sf_strerror#} handle) >>= E.throw code
+ peekCString ({#call pure sf_strerror#} handle) >>= E.throw . E.fromErrorCode code
-- ====================================================================
-- Handle operations

0 comments on commit 92d513e

Please sign in to comment.