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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:45:55+00:00 2026-05-26T08:45:55+00:00

compress xs@(_:_:_) = (ifte <$> ((==) <$> head <*> head.tail) <$> ((compress.).(:) <$> head

  • 0

compress xs@(_:_:_) = (ifte <$> ((==) <$> head <*> head.tail) <$> ((compress.).(:) <$> head <*> tail.tail) <*> ((:) <$> head <*> compress.tail) ) xs

Results in a type error, but I can’t see why. It should be equivalent to

compress xs@(_:_:_) = (ifte (((==) <$> head <*> head.tail) xs) (((compress.).(:) <$> head <*> tail.tail) xs) (((:) <$> head <*> compress.tail) xs))

, which doesn’t.

note: ifte = (\ x y z -> if x then y else z) , <$> and <*> are from Control.Applicative .

EDIT: The error is:

Couldn't match expected type `[a]' with actual type `[a] -> [a]'
    In the expression:
        (ifte <$> ((==) <$> head <*> head . tail)
     <$>
       ((compress .) . (:) <$> head <*> tail . tail)
   <*>
     ((:) <$> head <*> compress . tail))
      $ xs
    In an equation for `compress':
        compress xs@(_ : _ : _)
          = (ifte <$> ((==) <$> head <*> head . tail)
         <$>
           ((compress .) . (:) <$> head <*> tail . tail)
       <*>
         ((:) <$> head <*> compress . tail))
          $ xs

I encountered this problem trying to write a pointfree solution to problem 8 of the Ninety-Nine Haskell Problems. I was trying to do it by modifying the pointful solution I had written, which was

compress::Eq a => [a]->[a]
compress [] = []
compress (x:[]) = (x:[])
compress (x:y:xs) = ifte ((==) x y) (compress (x:xs)) (x:(compress (y:xs)))
  • 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-26T08:45:56+00:00Added an answer on May 26, 2026 at 8:45 am

    First, indent. Second, consider using some variables.

    Even with more sensible formatting, you can see that it’s

    compress =
      ifte <$> ((==) <$> head <*> head.tail)
           <$> ((compress.).(:) <$> head <*> tail.tail)
           <*> ((:) <$> head <*> compress.tail)
    

    when it should be

    compress =
      ifte <$> ((==) <$> head <*> head.tail)
           <*> ((compress.).(:) <$> head <*> tail.tail)
           <*> ((:) <$> head <*> compress.tail)
    

    Third, even if you must be inscrutable, how about

    compress (x:r@(y:_)) = ifte (x==y) id (x:) $ compress r
    

    or, point free

    compress = map fst . filter (uncurry (/=)) . (zip <$> id <*> tail)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Django-compress is great, but it doesn't offer any tags for compressing in-page javascript. Are
How can you compress inline script and style tags? YSlow says In addition to
I am wanting to compress results from QUERYS of the database before adding them
I'm looking to compress some lectures which are in MP3 format. Currently, they're each
i know we can compress response by declaring Response.Filter as GZip or Delfalte streams,
I want to compress an NSString. How I can do that in objective-c (iphone).
I compress my own JS using YuiCompressor, but is there any reason why MicrosoftAjax.js
I know how to compress an individual file using LZMA but it's not clear
how can I compress (minify) my JavaScript and CSS files dynamically in TYPO3? Thanks
I am trying to compress an AVI file using Visual Basic 6.0 but having

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.