summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-16 18:52:04 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-16 18:52:04 +0400
commited3aace2060792366edeac6cbe3ea415ac6db205 (patch)
tree12c43f8479825ffecd5375db4b2c52cf9aaee989 /src
parentfa7861cc092fb3d423d6e3c05df36d3651068de8 (diff)
Allow to catch fail :: Get a from pure code
Diffstat (limited to 'src')
-rw-r--r--src/Data/BEncode.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs
index 8768dac..a866a6e 100644
--- a/src/Data/BEncode.hs
+++ b/src/Data/BEncode.hs
@@ -643,7 +643,21 @@ endDict = Nil
643-- "length" < "md5sum" < "path" < "tags". 643-- "length" < "md5sum" < "path" < "tags".
644-- 644--
645newtype Get a = Get { runGet :: StateT BDict Result a } 645newtype Get a = Get { runGet :: StateT BDict Result a }
646 deriving (Functor, Applicative, Alternative, Monad) 646 deriving (Functor, Applicative, Alternative)
647
648-- | 'fail' is catchable from pure code.
649instance Monad Get where
650 return a = Get (return a)
651 {-# INLINE return #-}
652
653 Get m >>= f = Get (m >>= runGet . f)
654 {-# INLINE (>>=) #-}
655
656 Get m >> Get n = Get (m >> n)
657 {-# INLINE (>>) #-}
658
659 fail msg = Get (lift (Left msg))
660 {-# INLINE fail #-}
647 661
648-- | Get lexicographical successor of the current key\/value pair. 662-- | Get lexicographical successor of the current key\/value pair.
649next :: Get BValue 663next :: Get BValue