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 7438541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:34:14+00:00 2026-05-29T10:34:14+00:00

With the below snippet I want to append/prepend a string to a list that

  • 0

With the below snippet I want to append/prepend a string to a list that is part of a value stored in a map.

From the snippet below I get the error

Couldn't match expected type `Char' with actual type `[Char]'
    Expected type: Map.Map ([Char], Integer) [Char]
      Actual type: Map.Map ([Char], Integer) [[Char]]

and I am not quite sure what that should tell me. Can that be solved with a change in the code or must there be something like

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}

Together with an instance declaration?

import Data.Time
import Data.Time.Clock.POSIX
import qualified Data.PSQueue as PSQ
import qualified Data.Map as Map
import Data.Maybe
import Control.Category
import Control.Concurrent
import Control.Concurrent.MVar
import Control.Monad

key = ("192.168.1.1", 4711)
messages = ["aaa", "bbbb", "ccccc"]

newRq = do
      time <- getPOSIXTime
      let q = PSQ.singleton key time
      let m = Map.singleton key messages
      return (q, m)

appendMsg :: String -> (String, Integer) -> Map.Map ([Char], Integer) [Char] -> Map.Map ([Char], Integer) [Char]
appendMsg  a (b, c) m = m2
      where 
          f x = x ++ a
          m2 = Map.adjust f (b, c) m

main :: IO()
main = do
     (q, m) <- newRq
     let m2 = appendMsg "first" key m
     print (m2)
  • 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-05-29T10:34:15+00:00Added an answer on May 29, 2026 at 10:34 am

    You need a change in the code. You start with a Map (String, Integer) [String], by creating a singleton with value messages. Your update function however is written for Map (String, Integer) String. Either change it to the appropriate type by making it f x = x ++ [a] (and change the type signature to

    appendMsg :: String -> (String, Integer) -> Map (String, Integer) [String]
                                             -> Map (String, Integer) [String]
    

    too) or change your initial map by using e.g. unwords messages. (I think you’ll rather want the first.)

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

Sidebar

Related Questions

I want to modify the code snippet below in such a way, that I
I have this certain method(snippet below) for which I want to get the XML
In the code snippet below, from my jQuery setup, I need to check if
Below is a code snippet, where we retrieve a form value. Before further processing
See my code snippet below: var list = ['one', 'two', 'three', 'four']; var str
I'm trying to match the word first_name from the below snippet: <div class=field> <%=
How to send triimed data using $.get() see code snippet below: $(#txtSearch).keyup(function() { $.get(/controller/method/,
See my snippet below. I have a pretty good idea what the error is,
I've got a XML Schema (xsd file) snippet bellow, in which I want the
The snippet below is generating weird output: for s in servers: vo = ss.getServerVO(s)

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.