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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:36:54+00:00 2026-05-26T05:36:54+00:00

I recently started learning Haskell and I’m trying to rewrite something I did for

  • 0

I recently started learning Haskell and I’m trying to rewrite something I did for an interview in python in Haskell. I’m trying to convert a string from camel case to underscore separated (“myVariableName” -> “my_variable_name”), and also throw an error if the first character is upper case.

Here’s what I have:

import qualified Data.Char as Char

translate_java :: String -> String
translate_java xs = translate_helper $ enumerate xs
    where 
        translate_helper [] = []
        translate_helper ((a, num):xs)
            | num == 1 and Char.isUpper a = error "cannot start with upper"
            | Char.isUpper a              = '_' : Char.toLower a : translate_helper xs
            | otherwise                   = a : translate_helper xs


enumerate :: (Num b, Enum b) => [a] -> [(a,b)]
enumerate xs = zip xs [1..]

I realize It’s pretty likely I’m going about this in a weird way, and I’d love advice about better ways to implement this, but I’d like to get this to compile as well. Here’s the error I’m getting now:

Prelude> :r
[1 of 1] Compiling Main             ( translate.hs, interpreted )

translate.hs:4:20:
    No instance for (Num
                       (([Bool] -> Bool) -> (Char -> Bool) -> Char -> t))
      arising from a use of `translate_helper' at translate.hs:4:20-35
    Possible fix:
      add an instance declaration for
      (Num (([Bool] -> Bool) -> (Char -> Bool) -> Char -> t))
    In the first argument of `($)', namely `translate_helper'
    In the expression: translate_helper $ enumerate xs
    In the definition of `translate_java':
        translate_java xs
                         = translate_helper $ enumerate xs
                         where
                             translate_helper [] = []
                             translate_helper ((a, num) : xs)
                                                | num == 1 and Char.isUpper a
                                                = error "cannot start with upper
"
                                                | Char.isUpper a
                                                = '_' : Char.toLower a : transla
te_helper xs
                                                | otherwise = a : translate_help
er xs
Failed, modules loaded: none.

Any explanation of what’s going on here would be great. I really don’t understand where “(Num (([Bool] -> Bool) -> (Char -> Bool) -> Char -> t))” is coming from. I’d think the type declaration for translate_helper would be something like [(a,b)] -> [a]?

  • 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-26T05:36:55+00:00Added an answer on May 26, 2026 at 5:36 am

    The problem is this:

    | num == 1 and Char.isUpper a = ...
    

    and is not an infix operator; rather it is a function:

    and :: [Bool] -> Bool
    

    So it is interpreting 1 and Char.isUpper a as applying three arguments to the “function” 1. Use && instead.

    The error message comes from the way numerals are interpreted. A numeral, say, 1 is actually polymorphic; the specific type it gets depends on the type that is needed. That’s why you can say x+1 and it will work whether x is an integer or a double or whatever. So the compiler inferred that the type of 1 needs to be a three-argument function, and then tried to find a numeric type matching that so it could convert 1 into that type (and, naturally, failed).

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

Sidebar

Related Questions

I recently started learning Python and I was rather surprised to find a 1000
I recently started learning 0MQ . Earlier today, I ran into a blog, Python
I have recently started learning C++ and coming from a Ruby environment I have
I have recently started learning Python and I have 2 questions relating to modules.
I've just recently started learning HTML/CSS and I've been trying to teach myself sound
I have recently started learning wpf and am trying to use mvvm. My understanding
I jut recently started learning PHP from a book called PHP/MySQL Programming for the
I recently started learning DirectX/Windows, and the book I'm learning from had the code
I've recently started learning/using django; I'm trying to figure out a way to have
I have just recently started learning Haskell and I am having a lot of

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.