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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:35:26+00:00 2026-06-01T06:35:26+00:00

we started a paper on Haskell a few weeks ago and just received our

  • 0

we started a paper on Haskell a few weeks ago and just received our first assignment. I’m aware that SO doesn’t like homework questions, so I’m not going to ask how to do it. Instead, it would be very much appreciated if anyone could push me in the right direction with this. Seeing as it might not be a specific question, would it be more appropriate in a discussion / community wiki?

Question: Tokenize a String, that is: “Hello, World!” -> [“Hello”, “World”]

Coming from a Java background, I have to forget everything about the usual way to go about this. The problem is that I am still very clueless with Haskell. This is what I’ve come up with:

module Main where

main :: IO()
main = do putStrLn "Type in a string:\n"
          x <- getLine
          putStrLn "The string entered was:"
          putStrLn x
          putStrLn "\n"
          print (tokenize x)

tokenize :: String -> [String]
tokenize [] = []
tokenize l = token l ++ tokenize l

token :: String -> String
token [] = []
token l = takeWhile (isAlphaNum) l

What would be the first glaring mistake?
Thank you.

  • 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-01T06:35:28+00:00Added an answer on June 1, 2026 at 6:35 am

    The first glaring mistake is

    tokenize l = token l ++ tokenize l
    

    (++) :: [a] -> [a] -> [a] appends two lists of the same type. Since token :: String -> String (and type String = [Char]), the type of tokenize that is inferred from that line is tokenize :: String -> String.
    You should use (:) :: a -> [a] -> [a] here.

    The next mistake in that line is that in the recursive call, you pass the same input l once again, so you have an infinite recursion, always doing the same without change. You have to remove the first token (and a bit more) from the input for the argument to the recursive call.

    Another problem is that your token supposes that the input begins with alphanumeric characters.

    You also need a function that ensures that condition for what you pass to token.

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

Sidebar

Related Questions

EDIT I've just started skimming Codd's famous 1970 paper that started it all, that
I started using Raphael.js a few days ago and I'm really enjoying it. The
I started to integrate CUDA into my C++ applications weeks ago. I've been doing
Started working on a new application this week that is running the latest rails
I started programming C# applications when the 1.0 framework was first released. I worked
I just started working with jqGrid this week. I'm attempting to make a generic
Started researching Transfer ORM recently and find it pretty cool. Today I've noticed that
Started using PDO prepared statements not too long ago, and, as i understand, it
Started a webpage that now contains a lot of analytic data. Now that I
I am just getting started implementing ICU transforms using ICU4C in a C++ program.

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.