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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:26:34+00:00 2026-06-15T09:26:34+00:00

I have created this data type and function: type Bit = Int randomFloatList ::

  • 0

I have created this data type and function:

type Bit = Int

randomFloatList :: Int -> [Float]
randomFloatList seed = randoms (mkStdGen seed)

And I want to create a function that uses zipWith. The function has a seed as an argument that is used to the randomFloatList, if the random element is between 0 and noise then the bit is changed. I am trying to do it this way, but I am with difficulties with zipWith:

Thanks.

  • 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-15T09:26:35+00:00Added an answer on June 15, 2026 at 9:26 am

    I believe you want to take a list of Bits and use a random list to decide whether to alter the original. (If not, please clarify.)

    channel :: Int -> Float -> [Bit] -> [Bit]
    channel seed noise xs = zipWith (alterBit noise) (randomFloatList seed) xs
    

    Notice you didn’t need some of the brackets – you don’t need brackets for function application, just for grouping.

    alterBit :: Float -> Float -> Bit -> Bit
    alterBit noise random bit | random <= noise = alter bit
                              | otherwise = bit
    

    Again, I’ve removed any reference to the list that I’m using this with – zipWith will send this function the single elements it needs out of the list of floats and bits.

    I took the liberty of defining

    data Bit = O | I deriving Show
    

    and could only think of one alter function:

    alter :: Bit -> Bit
    alter O = I
    alter I = O
    

    Let’s test it:

    > take 6 $ randomFloatList 3
    [0.10321328,0.98988104,0.46191382,0.8553592,0.7980472,0.35561606]
    
    > map (<= 0.5) $ take 6 $ randomFloatList 3
    [True,False,True,False,False,True]
    
    > channel 3 0.5 [O,O,O,O,O,O]
    [I,O,I,O,O,I]
    

    Yup, that changed the ones it should.

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

Sidebar

Related Questions

I have an ggplot2 point chart created like this qplot(Index, Popularity ,data = data.slopeone.agg)
I have a Data Service created using WCF that internally uses nHibernate. This WCF
I have some data and need to create a json file with this structure
I have a data that looks like this . And I intend to create
If I have a table column with data and create an index on this
I have created this report using BIRT and phpjavabridge <?php header(Content-type: application/pdf); header(Content-Disposition: inline;
I have created this Fiddle with this code: This is my problem I want
I have created a structure of different data types and i want to return
I have a data set that resembles this: id product_id size color price created_date
I have created this simple program to learn shared_ptr using namespace std; #define Yes

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.