From dc004b45f8b499a4c35b08f8e18f641354f9b9d1 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 22 Oct 2019 14:52:47 +0200 Subject: Add custom GtkM state monad with a bind that does not grow the stack --- src/Gtk/State.dcl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/Gtk/State.dcl') diff --git a/src/Gtk/State.dcl b/src/Gtk/State.dcl index e97f3d3..2a5396c 100644 --- a/src/Gtk/State.dcl +++ b/src/Gtk/State.dcl @@ -2,11 +2,9 @@ definition module Gtk.State from StdMaybe import :: Maybe -from Control.Applicative import class pure -from Control.Monad.State import :: State, :: StateT, - instance pure (StateT m s) -from Control.Monad.Identity import :: Identity, - instance pure Identity +from Control.Applicative import class pure, class <*>, class Applicative +from Control.Monad import class Monad +from Data.Functor import class Functor from Data.Map import :: Map from Gtk.Signal import :: GSignalHandlerInternal @@ -18,12 +16,22 @@ from Gtk.Signal import :: GSignalHandlerInternal , signal_counter :: !Int } -:: GtkM a :== State GtkState a +:: GtkM a =: GtkM (GtkState -> (a, GtkState)) + +instance Functor GtkM +instance pure GtkM +instance <*> GtkM +instance Monad GtkM +where + (>>|) infixl 1 :: (GtkM a) (GtkM b) -> GtkM b newGtkState :: GtkState runGtk :: !(GtkM a) !*World -> (!a, !*World) +getState :: GtkM GtkState +modState :: !(GtkState -> GtkState) -> GtkM GtkState + toState :: !(A.a: a -> a) -> GtkM () toStateR :: !(A.a: a -> (r,a)) -> GtkM r -- cgit v1.2.3