David Roundy wrote:
Try

module Secret (Secret, classify, declassify)
where

data Secret a = Secret String a

classify :: String -> a -> Secret a
classify pw x = Secret pw x

declassify :: Secret a -> String -> Maybe a
declassify (Secret pw x) pw' | pw' == pw = Just x
declassify (Secret _ _) _ = Nothing

instance Monad Secret where
   return = classify ""
   (Secret pw x) >>= f = case f x of
                         Secret _ y -> Secret pw y

That's just the sort of thing I was looking for.  Thanks!

Arie Peterson wrote:
What should 'q >>= r' mean, when 'q' and 'r x' are secrets with different
passwords? In the code above, the result is a secret with the same
password as 'q'. This allows you to declassify any secret without knowing
its password:

Yeah, but I think that's easy to fix: make classify and declassify take a set of strings rather than a single string, and then make >>= return a secret containing the union of passwords on both sides.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to