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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:58:01+00:00 2026-05-27T09:58:01+00:00

I have this code that I tried to create to count amount of records

  • 0

I have this code that I tried to create to count amount of records and print them, I cant seem to get it working I constantly get errors about a function reportReg being applied to one argument but its type [String] having none.

report :: [[String]] -> String -> [String]
report (x:xs) typ = do
                    case typ of
                        "registrations" -> reportReg (map head xs)
                        "completions" -> reportReg (map head xs)

reportReg :: [String]
reportReg [x] = do
                    print x
                    print 1
reportReg (x:xs) = do 
                    let count = instances x (x:xs)
                    print x
                    print count
                    let newlist = filter (==x) (x:xs)
                    reportReg newlist

instances::String->[String]->Int
instances x [] = 0
instances x (y:ys)
    | x==y = 1+(instances x ys)
    | otherwise = instances x ys

Also, is there an easier way to do this?

  • 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-27T09:58:02+00:00Added an answer on May 27, 2026 at 9:58 am

    Problem:

    You’ve given reportReg a type of list of string:

    reportReg :: [String]
    

    This is simply a value, or a function of 0 arguments. That explains the error you were getting — trying to give it an argument, but it takes none.

    Solutions:

    • It looks like you want to do IO actions in reportReg, so you should change the type annotation:

      reportReg :: [String] -> IO ()
      

    — or —

    • write the function without a type annotation, let Haskell infer it for you, and then copy down that annotation

    Problem:

    report‘s return type is wrong. It has to be the same as that of reportReg. But reportReg :: String -> IO (), whereas report :: [[String]] -> String -> [String]!

    A couple possible solutions:

    • remove IO actions from reportReg, so that its type is [String] -> [String]. I’d strongly suggest doing this — IO in any language is always a pain, but the cool thing about Haskell is that it makes you feel the pain — thereby giving you an incentive to avoid IO as much as possible!
    • change type of report to [[String]] -> String -> IO ()

    Lazy man’s solution:

    I copied your code into a text file, removed the annotations (making no other changes), and loaded it into ghci:

    Prelude> :load typef.hs 
    [1 of 1] Compiling Main             ( typef.hs, interpreted )
    Ok, modules loaded: Main.
    *Main> :t report
    report :: (Eq a, Show a) => [[a]] -> [Char] -> IO ()
    *Main> :t reportReg 
    reportReg :: (Eq a, Show a) => [a] -> IO ()
    *Main> :t instances 
    instances :: (Num t, Eq a) => a -> [a] -> t
    

    It works — Haskell infers the types! But it may not do what you want.

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

Sidebar

Related Questions

I have this code that works in a unit test but doesn't work when
I have this code that I want to make point-free; (\k t -> chr
I have this code that fetches some text from a page using BeautifulSoup soup=
I have this code that changes the opacity of the div on hover. $(#navigationcontainer).fadeTo(slow,0.6);
I have this code that has one button that let's me choose an entry
I have this code that saves a pdf file. FileStream fs = new FileStream(SaveLocation,
i have this code that will check the array contains the specific string and
I have this code that asks for a username and password. Just a simple
I have this code that makes a string and then echos the loop out
I have this code that will check for if the class more-results are in

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.