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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:12:02+00:00 2026-06-01T02:12:02+00:00

Hello I am new at Haskell and i’m having problems trying to get this

  • 0

Hello I am new at Haskell and i’m having problems trying to get this script to work. This script reads in arguements from a command line and find them in a seperate text file.

E.G: cat.txt | ./redact house big cat (in compiler)

It redacts certain words in a text file by replacing them with stars (**)asterisks. The number of stars used for each redacted word should equal the number of characters in the word.

module Main where

import System
import Data.Char
import Data.List

lowercase :: String -> String
lowercase = map toLower

main = do 
arg1 <- getArgs
txt <- getContents
putStr (redact txt arg1)

redact :: String -> String -> String
redact input xWords = unlines [ work line | line <- lines input ]
where work line = unwords [ foo word | word <- words line ]
  foo w | lowercase(w) == lowercase(xWords) = convertWord w 1
    | otherwise                         = w

convertWord Eq a => [a] -> [a]
convertWord = map (const '*') 

However, when i try to compile this, GHCi returns the error:

redact.hs:13:38:
    Couldn't match expected thye 'Char' with actual type '[Char]'
    Expected type: String
     Actual type: [String]
    In the second argument of 'redact', namely 'arg1'
    In the first of 'putStr', namely '<redact txt arg1>'
Failed, module loaded: none.

So the code:

putStr (redact txt arg1)

is causing the problem.

Thank you in advance for any help and if you can improve the code in anyway that would be great.

EDIT:

I want to enter as many args as possible, it doesnt matter how many args you enter, i tried:

(arg1:arg2:arg3:arg4:arg5:_) <- getArgs

but I have to enter EXACT 5 args, It shouldn’t matter how many args I enter.
I was thinking of using some kind of loop but I am not sure?

Again thank you for your help.

  • 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-01T02:12:03+00:00Added an answer on June 1, 2026 at 2:12 am

    To get it to work with multiple arguments, use getArgs as you have it. The problem lies with

    foo w | lowercase(w) == lowercase(xWords) = convertWord w 1
          | otherwise                         = w
    

    where you compare the lowercase of one word to lowercase of multiple words. The latter is not defined, you’d like to compare it to the lowercase of each of the xWords. So first you need to bring them all to lowercase, that’s most efficiently done by calling from main redact txt (map lowercase arg1) rather than just redact txt arg1. Then you need to determine if a read word is in the list xWords, that’s what the elem function is there for.

    foo w | lowercase w `elem` xWords = convertWord w 1
          | otherwise                 = w
    

    BTW, you should maybe not call this function foo even if it’s only a local one.

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

Sidebar

Related Questions

hello I'm new to PHP programming and I migrated from ASP .net to PHP..
hello im new and learning javascript. I'm trying to make a program of addition
Hello im new to programming, im trying to construct my first simple application, im
class Hello @hello = hello def display puts @hello end end h = Hello.new
Hello I'm new to ontologies, my assignment is to create an ontology using Protege
C:\>irb irb(main):001:0> s = Proc.new { puts Hello } => #<Proc:0x04051780@(irb):1> irb(main):002:0> s.call Hello
hello friends i m new to jQuery and nyro modal. right now i m
Hello everyone I am new to blackberry and I want a textfield that scroll
Hello there and Merry Christmas !!! I am new to WPF and I am
Possible Duplicate: New Cool Features of C# 4.0 Hello, There are several(many) questions at

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.