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

  • Home
  • SEARCH
  • 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 8738507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:44:40+00:00 2026-06-13T10:44:40+00:00

I have the code which create Data.Map: import qualified Data.Map as Map shift_string ::

  • 0

I have the code which create Data.Map:

import qualified Data.Map as Map

shift_string :: [Char] -> Int -> [Char]
shift_string s num = (drop num s) ++ (take num s)

ascii :: [Char]
ascii = ['a' .. 'z']

shifted_ascii :: Int -> [Char]
shifted_ascii n = shift_string ascii n

trans_table :: Int -> Map.Map Char Char
trans_table n = Map.fromList(zip ascii $ shifted_ascii n)

The ‘trans_table’ function returns the Map where one Char map to another map.
I can create the function to get one Char and return another one based on this Map:

translate_char :: Char -> Int -> Maybe Char
translate_char c n = Map.lookup c $ trans_table n

Now I want to ‘translate’ each symbol in the map. Something like this:

encode message key = map translate_char message

This code doesn’t work as translate_function must have only one parameter. I need something like global variable to store the Map in it and lookup values from it in my map-function. But I don’t know how to rewrite my code.

p.s. I guess I can just add ‘key’ to each char in my string but I am searching common solution.

  • 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-13T10:44:42+00:00Added an answer on June 13, 2026 at 10:44 am

    I don’t know whats key in your encode function but you can use something like

    translate_char :: Int -> Char -> Maybe Char
    translate_char n c = Map.lookup c $ trans_table n
    
    encode :: Int -> String -> String
    encode n s = catMaybes $ map (translate_char n) s
    

    here n determines the number of characters you are rotating. I switched the order of parameters to avoid using flip.

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

Sidebar

Related Questions

I have this code which should create a splash image with either no animation
I have the following code which creates a simple window with two buttons which
I have the following code which creates an ImageButton and plays a sound when
I have the following code which creates a new table. var html = '<table>';
I have created some python code which creates an object in a loop, and
I have the following code which is created with a datalist control: http://jsfiddle.net/vmE2E/1/ But
I have this code, which creates an image, and then adds some effects to
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
I have created a piece of code which takes an IP address (from main
In my project, I have created a code snippet which can be copied and

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.