<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>XMonad.Util.ExtensibleState</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[ window.onload = function () {pageLoad();setSynopsis("mini_XMonad-Util-ExtensibleState.html");}; //]]> </script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/XMonad-Util-ExtensibleState.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">xmonad-contrib-0.11: Third party extensions for xmonad</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Portability</th><td>not portable</td></tr><tr><th>Stability</th><td>unstable</td></tr><tr><th>Maintainer</th><td>daniel.schoepe@gmail.com</td></tr><tr><th>Safe Haskell</th><td>Safe-Infered</td></tr></table><p class="caption">XMonad.Util.ExtensibleState</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Usage </a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Module for storing custom mutable state in xmonad. </p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><a href="#v:put">put</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => a -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:modify">modify</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => (a -> a) -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:remove">remove</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => a -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a></li><li class="src short"><a href="#v:get">get</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> a</li><li class="src short"><a href="#v:gets">gets</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => (a -> b) -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> b</li></ul></div><div id="interface"><h1 id="g:1">Usage </h1><div class="doc"><p>To utilize this feature in a contrib module, create a data type and make it an instance of ExtensionClass. You can then use the functions from this module for storing and retrieving your data: </p><pre> {-# LANGUAGE DeriveDataTypeable #-} import qualified XMonad.Util.ExtensibleState as XS data ListStorage = ListStorage [Integer] deriving Typeable instance ExtensionClass ListStorage where initialValue = ListStorage [] .. XS.put (ListStorage [23,42]) </pre><p>To retrieve the stored value call: </p><pre> .. XS.get </pre><p>If the type can't be inferred from the usage of the retrieved data, you have to add an explicit type signature: </p><pre> .. XS.get :: X ListStorage </pre><p>To make your data persistent between restarts, the data type needs to be an instance of Read and Show and the instance declaration has to be changed: </p><pre> data ListStorage = ListStorage [Integer] deriving (Typeable,Read,Show) instance ExtensionClass ListStorage where initialValue = ListStorage [] extensionType = PersistentExtension </pre><p>One should take care that the string representation of the chosen type is unique among the stored values, otherwise it will be overwritten. Normally these string representations contain fully qualified module names when automatically deriving Typeable, so name collisions should not be a problem in most cases. A module should not try to store common datatypes(e.g. a list of Integers) without a custom data type as a wrapper to avoid collisions with other modules trying to store the same data type without a wrapper. </p></div><div class="top"><p class="src"><a name="v:put" class="def">put</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => a -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a><a href="src/XMonad-Util-ExtensibleState.html#put" class="link">Source</a></p><div class="doc"><p>Add a value to the extensible state field. A previously stored value with the same type will be overwritten. (More precisely: A value whose string representation of its type is equal to the new one's) </p></div></div><div class="top"><p class="src"><a name="v:modify" class="def">modify</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => (a -> a) -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a><a href="src/XMonad-Util-ExtensibleState.html#modify" class="link">Source</a></p><div class="doc"><p>Apply a function to a stored value of the matching type or the initial value if there is none. </p></div></div><div class="top"><p class="src"><a name="v:remove" class="def">remove</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => a -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> <a href="/usr/share/doc/ghc/html/libraries/ghc-prim-0.2.0.0/GHC-Tuple.html#t:-40--41-">()</a><a href="src/XMonad-Util-ExtensibleState.html#remove" class="link">Source</a></p><div class="doc"><p>Remove the value from the extensible state field that has the same type as the supplied argument </p></div></div><div class="top"><p class="src"><a name="v:get" class="def">get</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> a<a href="src/XMonad-Util-ExtensibleState.html#get" class="link">Source</a></p><div class="doc"><p>Try to retrieve a value of the requested type, return an initial value if there is no such value. </p></div></div><div class="top"><p class="src"><a name="v:gets" class="def">gets</a> :: <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:ExtensionClass">ExtensionClass</a> a => (a -> b) -> <a href="/usr/share/doc/ghc/html/libraries/xmonad-0.11/XMonad-Core.html#t:X">X</a> b<a href="src/XMonad-Util-ExtensibleState.html#gets" class="link">Source</a></p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.10.0</p></div></body></html>