[server] Add return value to tree modules

Now, tree modules can't just stop, they can Just stop. Sorry... But they can
return values now, with a tiny bit of type class trickery.
This commit is contained in:
Joscha 2020-02-13 23:38:26 +00:00
parent 220b5a3234
commit 2a2b148046
6 changed files with 55 additions and 39 deletions

View file

@ -1,3 +1,5 @@
{-# LANGUAGE MultiParamTypeClasses #-}
module Forest.TreeModule
( TreeModule(..)
, ModuleConstructor
@ -7,17 +9,17 @@ import qualified Data.Text as T
import Forest.Node
class TreeModule a where
edit :: a -> Path -> T.Text -> IO Bool
edit _ _ _ = pure True
class TreeModule a r where
edit :: a r -> Path -> T.Text -> IO (Maybe r)
edit _ _ _ = pure Nothing
delete :: a -> Path -> IO Bool
delete _ _ = pure True
delete :: a r -> Path -> IO (Maybe r)
delete _ _ = pure Nothing
reply :: a -> Path -> T.Text -> IO Bool
reply _ _ _ = pure True
reply :: a r -> Path -> T.Text -> IO (Maybe r)
reply _ _ _ = pure Nothing
act :: a -> Path -> IO Bool
act _ _ = pure True
act :: a r -> Path -> IO (Maybe r)
act _ _ = pure Nothing
type ModuleConstructor a = (Node -> IO ()) -> (a -> IO ()) -> IO ()