LoginSignup
0
0

More than 5 years have passed since last update.

Data.Vault

Posted at

任意の型をしまえるコンテナ(といっても当然破壊的変更はできない)。

% runhaskell
module Main (main) where
import           Data.Vault (Vault)
import qualified Data.Vault as V

sayHello :: Show a => V.Key a -> Vault -> IO ()
sayHello key v = maybe (return ()) print (V.lookup key v)

main :: IO ()
main = do
  poti <- V.newKey
  zero <- V.newKey :: IO (V.Key Int)
  let v = (V.insert zero 0 . V.insert poti "poti") V.empty
  sayHello zero v
  sayHello poti v

キーに型情報が入っているのでうまくいく。キーの生成にSTIOのモナドが必要。

0
"poti"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0