[Haskell-cafe] Re: a monad for secret information

Seth Gordon sethg at ropine.com
Tue Oct 10 20:41:09 EDT 2006


> 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.



More information about the Haskell-Cafe mailing list