Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added hashBinary helper to Hash, and switched the type arguments to R…

…equest (to be left-to-right in the mapping needed).
  • Loading branch information...
commit 030fafc2d2b60fde8d66010423edf2e55b8faf5e 1 parent 7de891d
@luqui authored
Showing with 8 additions and 5 deletions.
  1. +4 −1 Udon/Hash.hs
  2. +4 −4 Udon/Request.hs
View
5 Udon/Hash.hs
@@ -1,5 +1,5 @@
module Udon.Hash
- ( Blob, Hash, hashBlob )
+ ( Blob, Hash, hashBlob, hashBinary )
where
import qualified Data.ByteString.Lazy as Str
@@ -17,3 +17,6 @@ instance Binary Hash where
hashBlob :: Blob -> Hash
hashBlob = Hash . Str.pack . SHA.hash . Str.unpack
+
+hashBinary :: (Binary a) => a -> Hash
+hashBinary = hashBlob . encode
View
8 Udon/Request.hs
@@ -9,7 +9,7 @@ import Control.Monad
import Control.Arrow hiding (pure)
import Data.Monoid
-newtype ReqList i o a = ReqList [(o, i -> a)]
+newtype ReqList i o a = ReqList [(i, o -> a)]
instance Functor (ReqList i o) where
fmap f (ReqList xs) = ReqList ((fmap.second.fmap) f xs)
@@ -46,15 +46,15 @@ instance Monad (Request i o) where
fapp x ff = ff <*> pure x
-request :: o -> Request i o i
+request :: i -> Request i o o
request o = Request (ReqList [(o, Return)])
-runRequest :: Request i o a -> Either [(o, i -> Request i o a)] a
+runRequest :: Request i o a -> Either [(i, o -> Request i o a)] a
runRequest (Return x) = Right x
runRequest (Request (ReqList l)) = Left l
-runRequestHandler :: (Monad m) => (o -> m i) -> Request i o a -> m a
+runRequestHandler :: (Monad m) => (i -> m o) -> Request i o a -> m a
runRequestHandler handler req =
case runRequest req of
Right x -> return x
Please sign in to comment.
Something went wrong with that request. Please try again.