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

The Archive Base Latest Questions

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

I want to program a function that generates a String. The String contains only

  • 0

I want to program a function that generates a String. The String contains only 1,0,s and S.
The numbers are binary numbers. Each number is separated through a s. And a number gives the length of the rest of the String. The capital S is the end of the String.

Examples:

func :: Integral a => a -> String

func 1

"1S"

func 3

"110s11s1S"

func 4

"1010s110s11s1S"

My problem is, that I don’t know, how I can get the length of the tail ("s1S" -> tail, 11 -> head) and than get the new tail.

My new code:

>toBinary :: Integral a => a -> String
>toBinary 0 = []
>toBinary x
>       | mod x 2 == 0 =  '0' : toBinary (div x 2) 
>       | mod x 2 == 1 =  '1' : toBinary (div x 2)

>zubinaer :: Integral a => a -> String
>zubinaer x = reverse (toBinary x)
>
>distan :: Integral a => a -> String
>distan n = if n > 0 then hilfsfunktion (n-1) "1S" else  []
>   
>       where
>           hilfsfunktion :: Integral a => a -> String -> String
>           hilfsfunktion 0 s = s
>           hilfsfunktion n s = hilfsfunktion (n-1) (zubinaer(length s + 1) ++ "s" ++ s )

Here my older code: http://hpaste.org/54863

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

    I think you are tackling your problem from the wrong angle. In Haskell, one often thinks of lists. Actually, a String is just a list of Chars. Try to build your function from these bricks:

    • Write a function toBinary :: Integral a => a -> [Bool] that outputs a binary representation of its parameters. A 1 is True and a 0 is False
    • You can use map to turn the [Bool] into a String by replacing each boolean by a character 0 or 1.
    • You can use the syntax [1..n] to generate a list of integers from 1 to n. Use map to generate a list of binary representation strings.
    • Use intercalate from Data.List to create your string.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a paint program that has no save function. I want to know
I want to make some C++ program and I'm using function popen here to
I have this program that I want other processes to be able to call
I want to overload a function so that it manipulates its argument in some
I have a program that uses the mt19937 random number generator from boost::random. I
I want to write a Python program that makes PNG files. My big problem
For my program I am trying to create a function that will generate an
I want my program to change its window's caption in response to various user
I want to program a board game (similar to checkers) for the iPhone. Would
I want to program something in both C# and F#. I have partial classes

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.