Help me with this event handler pls

41 views
Skip to first unread message

cohomology

unread,
Jan 27, 2017, 10:11:26 AM1/27/17
to Brick Users
I am making an interactive net client (think a chat client or Mud client). For my app I have a viewport to display messages received from the server and an edit to capture the user input. I have defined this simple State for my app

data UIState =
     
UIState { _cli     :: E.Editor Text Name   -- Editor widget to input commands
             
, _output  :: Text                   -- Output received from the host
             
, _history :: [Text]                 -- History of commands inputed by user
             
, _cmd     :: Text                   -- Current command, possibly incomplete
             
, _handle  :: IO Handle
             
}

I want to overide the behavior of the Enter key. When the Enter key is pressed I want to send the user input to the server. Here is the handler I wrote:



appEvent st ev =
   
case ev of
         T
.VtyEvent (V.EvKey V.KEnter [])
             
-> do
                    let current
= head $ E.getEditContents (st^.cli)
                   
(lift ( E.applyEdit (const ""))) (st^.cli)
                    liftIO $ hPutStrLn
(st^.handle) $ encodeUtf8(current)
                    M
.continue (st & cmd .~ current & history %~ ( ++ [current]))

You can see I am trying to do several things here:
  1. get the user input
  2. clear the editor
  3. send the input to the server
  4. update the State accordingly and continue the app
However I couldn't make the code compile. For the applyEdit line I get the following error

   
Couldn't match kind `* -> *' with `*'
    Expected type: E.Editor Text Name -> T.EventM Name a0
      Actual type: E.Editor Text Name -> T.EventM Name a0
    Kind incompatibility when matching types:
      E.Editor Text Name :: * -> *
      E.Editor Text Name :: *
    The function `
lift'ghc: panic! (the 'impossible' happened)
  (GHC version 7.6.3 for x86_64-unknown-linux):
        kindFunResult ghc-prim:GHC.Prim.*{(w) tc 34d}

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

I don't understand what is wrong here. So how do you call applyEdit in an event handler?




and for the hPutStrLn I get


    Couldn't match type `IO Handle' with `Handle'
    Expected type: Getting Handle UIState Handle
      Actual type: (IO Handle -> Const Handle (IO Handle))
                   -> UIState -> Const Handle UIState
    In the second argument of `
(^.)', namely `handle'
   
In the first argument of `hPutStrLn', namely `(st ^. handle)'
    In the expression: hPutStrLn (st ^. handle)


I understand that I am feeding "IO Handle" instead of "Handle" to the function but I just cannot find a way to fix it.

Please help!
Reply all
Reply to author
Forward
0 new messages