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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:02:59+00:00 2026-06-06T17:02:59+00:00

Edit: it’s hard to describe what I’m trying to do, but here’s a try

  • 0

Edit: it’s hard to describe what I’m trying to do, but here’s a try (from the comments):

I am building a wordfeud solver, so I have a word, and some letters (both char list). I applied this ( How to find the frequency of characters in a string in Haskell? ) to both lists to get the frequency of all letters. What I’m doing now is iterating though the ‘word’ char list, and checking if all chars occur sufficiently in the ‘letters’ char list.

I have written a Haskell function that compares two lists by applying a function to the items of both lists, and comparing the results.

The comparison is done like this:

hasLetters' :: [Char] -> [Char] -> Bool
hasLetters' word letters = (getCharOccurrence (head word) (getCharOccurrences word)) <= (getCharOccurrence (head word) (getCharOccurrences letters))

This only compares the occurrences of the first letter of the word. But ALL words should be compared (and the result should be TRUE for all of them).

I don’t really know how to accomplish this. I found the ‘all’ method that lets me define a predicate, that’s pretty good. It looks like this:

all (<= (getCharOccurrence (head word) (getCharOccurrences letters))) 

(I think that’s correct)
It makes sure that every item that goes into the list is smaller than or equal to the result of the provided function.

BUT: the ‘all’ method needs another parameter. This would be the ‘source’ parameter that defines what should be compared to the predicate. This would be easy when this were just a list, then I would do something like this:

all (<= (getCharOccurrence (head word) (getCharOccurrences letters))) [0..10]

But the problem is: I dont have a list of results like this, I need to compare it to the result of:

(getCharOccurrence (head word) (getCharOccurrences letters))

I figured that I could apply this function to every character in the ‘word’ char list with the ‘map’ function, but I dont know how to use it. I started like this:

map (getCharOccurrence (head word) (getCharOccurrences word)) word

But that’s wrong.

So what I (think I) need: apply the above function to all characters of the ‘word’ char list, and compare it to the predicate.

But maybe I’m just think the wrong way. I’m an absolute Haskell/functional programming newbie. Please help me out 🙂

  • 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-06T17:03:00+00:00Added an answer on June 6, 2026 at 5:03 pm

    So from what I understand you have a string word with the word you would like to form and a list of chars letters representing the tiles at your disposal. You want to check whether the word may be formed by the tiles or not.

    Here I’m assuming the functions you’ve mentioned have the types

    getCharOccurrence :: Char -> [(Char, Integer)] -> Integer
    getCharOccurrences :: [Char] -> [(Char, Integer)]
    

    First, you need to modify hasLetters' to take a Char parameter instead of using head word:

    hasLetters' :: Char -> [Char] -> [Char] -> Bool
    hasLetters' c word letters = (getCharOccurrence c (getCharOccurrences word)) <= (getCharOccurrence c (getCharOccurrences letters))
    

    Then you can combine the above to a master function (let’s call it sufficientTiles) with

    sufficientTiles :: [Char] -> [Char] -> Bool
    sufficientTiles word letters = and $ map (\c -> hasLetters' c word letters) word
    

    What we’ve done here is to map the hasLetter' function to each character of word. This will give us a list of Bools. We then use and to check that all elements of that list are True.

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

Sidebar

Related Questions

EDIT: I'll try and make it clearer sorry for the confusion. I have two
EDIT : I have edited the OP with all the suggestions I got from
EDIT: See my answer below--> I am wanting to have a view that when
Edit (updated question) I have a simple C program: // it is not important
EDIT: Here is the edited control file (control.ascx): <%@ Control Language=C# AutoEventWireup=true CodeFile=Sale.ascx.cs Inherits=Enmasse.Modules.Demo_Enmasse.Sale
Edit: The below question was answered by this . I have a new updated
EDIT: Changed as I have a different issue with the same code 2nd Edit:
EDIT Leaving this for posterity, but nearly a year later, to get down voted,
Edit ok, great feedback here, got me pointed in the right direction. Use case
EDIT: More detail here. Basically if you 1. open a tab1 to url1 (GET

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.