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

The Archive Base Latest Questions

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

I’m doing a project that aims to create a PDF using the exiftool library

  • 0

I’m doing a project that aims to create a PDF using the exiftool library and language Haskell and I have some doubts in the creation of functions to order the files. My work originates as PDF now lacks the sorting functions. For example for my dat.hs file contains these files (music, videos)

Files {files = [{filename = Video "-4th_dan trailer.mp4" size = "15 MB" ftype = "MP4" copyright = "-" height = "-", width = "720"}
Video {filename = "TheLostInterview.mp4" size = "73 MB" ftype = "MP4" copyright = "-" height = "Bruce_Lee_-_The_Lost_Interview.avi" width = "240"}
Audio {filename = "8bp017-08-nullsleep-humdrumz.mp3" size = "1984 kb", ftype = "MPG / 3" copyright = "-", title = "humdrumz" artist = "nullsleep", year = "2001"}
Audio {filename = "8bp017-04-nullsleep-fluffy_nougat.mp3" size = "1501 kb", ftype = "MPG / 3" copyright = "-", title = "fluffy nougat," artist = "nullsleep" year = "2001"}

I now through functions such as sortOn :: (Ord b) => (a -> b) -> [a] -> [a] and select ((> 500). size) (dat files) have to organize these files by size, year, artist …

Now one problem is the size because I want to sort by size and the size he is set to “15 MB” the MB has to be able to sort out there to
`

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

    If I understood correctly, you want 15 MB to be considered bigger than 1984 kb.

    One way to do this would be to use sortBy rather than sortOn. sortBy takes a comparison function and sorts using that. So you can just write a function that can sort values like 15 mb properly.

    However, this is not the best way to do it. Instead, I suggest you normalize all the sizes to one unit (kb, perhaps). So go through and convert 15 MB to kilobytes and store it as a number. Then, when you need to print the sizes, have a function that takes a number of kb and prettifies it. This will allow you to easily sort on size.

    A way to do this would be to create a Size type:

    newtype Size  = Size Integer deriving (Eq, Ord)
    

    Then you can make it an instance of Show to get the pretty printing working:

    instance Show Size where
      show (Size s)
        | s < 1000 = show s ++ " kB"
        | s < 1000000 = show (s `div` 1000) ++ " mB"
        | otherwise = show (s `div` 1000000) ++ " gB"
    

    To get the size from the input string, you could make it an instance of Read.

    instance Read Size where
      readsPrec _ str = do (size, rest)  <- reads str
                           (unit, rest') <- lex rest
                           let multiplier = fromMaybe 1 $ lookup unit unitSizes
                           return (Size $ multiplier * size, rest')
        where unitSizes = [("mB", 1000), ("gB", 1000000)]
    

    You can include variants of unit names (e.g. “mB” and “MB”) just by adding more pairs to unitSizes. Any unit abbreviation not in the list is just ignored.

    Edit: Made the code neater by using Daniel Wagner’s suggestion.

    Additional notes:

    Once you’ve defined Size and made it an instance of all of those type classes, you can use normal sorts on it. You can use read on things like "10 mB" to get the size. If you use deriving (show) on your original data type, it should still work when you replace your strings with Sizes.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

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.