blob: 48db8ebdcbd7acc70566dfe4f8d8ce9a479d5c48 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
definition module Gtk.Shares
/**
* This module provides shares in the `GtkM` monad, allowing the programmer to
* abstract from global state. They are loosely based on SDSs in iTasks, but
* much less advanced.
*/
from Gtk.State import :: GtkM
//* Identifier of a share.
:: ShareId :== String
//* Exported to have a TC instance --- do not use directly!
:: Shared a :== (String,a)
//* Types must instantiate this class to be able to be shared.
class shared a | TC a
//* Sets up a share with a default value (cf. iTasks' `sharedStore`).
share :: !ShareId a -> Shared a | shared a
getShared :: !(Shared a) -> GtkM a | shared a
setShared :: !(Shared a) !a -> GtkM a | shared a
updateShared :: !(a -> a) !(Shared a) -> GtkM a | shared a
/**
* A share with an initialization function. It will always return the same
* value, namely the result of the initialization function, but that function
* will only be evaluated once. It can be seen as an impure CAF.
*/
singletonShared :: !String !(GtkM a) -> GtkM a | shared a
//* Evaluate a function with a temporary share.
withShared :: a !((Shared a) -> GtkM b) -> GtkM b | shared a
|