Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:53:42+00:00 2026-06-17T21:53:42+00:00

I have this function which is responsible for communication in a web chat. Everything

  • 0

I have this function which is responsible for communication in a web chat. Everything works fine without t <- getClockTime (here is code with it):

talk :: WS.Protocol p => MVar State -> Client -> WS.WebSockets p ()
talk state client@(user, sink) = flip WS.catchWsError catchDisconnect $ 
  forever $ do
    t <- getClockTime
    msg <- WS.receiveData
    case () of
      () | T.unpack(msg) == "#list" -> liftIO $ readMVar state >>= listClients client
        | T.unpack(msg) == "#time" -> liftIO (sendTime client)
        | "#name" `T.isPrefixOf` msg -> liftIO (command msg client)
        | otherwise -> liftIO $ readMVar state >>= broadcast
          (user `mappend` msg)
  where
    catchDisconnect e = case fromException e of
        Just WS.ConnectionClosed -> liftIO $ modifyMVar_ state $ \s -> do
            let new_state = removeClient client s
            return new_state
        _ -> return ()

With t <- getClockTime I get error:

Couldn't match type `WS.WebSockets p0' with `IO'
Expected type: IO Text
  Actual type: WS.WebSockets p0 Text
In a stmt of a 'do' block: msg <- WS.receiveData
In the second argument of `($)', namely
  `do { t <- getClockTime;
        msg <- WS.receiveData;
        case () of {
          ()
            | T.unpack (msg) == "#list"
            -> liftIO $ readMVar state >>= listClients client
            | T.unpack (msg) == "#time" -> liftIO (sendTime client)
            | "#name" `T.isPrefixOf` msg -> liftIO (command msg client)
            | otherwise
            -> liftIO $ readMVar state >>= broadcast (user `mappend` msg) } }'
In the second argument of `($)', namely
  `forever
   $ do { t <- getClockTime;
          msg <- WS.receiveData;
          case () of {
            ()
              | T.unpack (msg) == "#list"
              -> liftIO $ readMVar state >>= listClients client
              | T.unpack (msg) == "#time" -> liftIO (sendTime client)
              | "#name" `T.isPrefixOf` msg -> liftIO (command msg client)
              | otherwise
              -> liftIO $ readMVar state >>= broadcast (user `mappend` msg) } }'

How can I get this time and concatenate it with msg?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:53:43+00:00Added an answer on June 17, 2026 at 9:53 pm

    Because your monad isn’t IO. I have no idea what WS.WebSockets is, but if it’s this one, it’s an instance of MonadIO, so you can use liftIOgetClockTime. I recommend reading more about monad transformers for this sort of code, because lifting is going to come up a lot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have this anonymous function in our code, which is part of the jQuery's
I have this function which is supposed to set a certain time format to
I have this function which pings my server for a specific change in data:
I have this function which gives me ( for a current date ) -
I have this function which returns a datatype InetAddress[] public InetAddress [] lookupAllHostAddr(String host)
Hi have made this function which is made to replicate an error that I
I have a function which calculates distance from database records. This function is called
I have a function (function1) which requires sta mode. I'd like tocall this function
I have this istuation. I have a setTimeout to a function in which I
I have a function which looks something like this, it returns a noncopyable class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.