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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:00:38+00:00 2026-06-03T07:00:38+00:00

i need help about a rotation or spin matrix in haskell i have a

  • 0

i need help about a rotation or spin matrix in haskell

i have a list of list, of a data type RGB:

data RGBdata= RGB Int Int Int

m = [[(RGB 0 255 255),(RGB 255 0 0)],[(RGB 255 255 255),(RGB 255 0 0)]]

to be seen better i have a matrix 2×2:

m = [[(RGB 1 2 3),(RGB 4 5 6)],
     [(RGB 7 8 9),(RGB 1 5 9)]]

and i need 90° rotation, i mean something like:

m = [[(RGB 7 8 9),(RGB 1 2 3)]
     [(RGB 1 5 9),(RGB 4 5 6)]]

Extends my explication, i have 2 data type:

data RGBdata= RGB Int Int Int
data PBMfile= PBM Int Int [[RGBdata]]

and my function receive:

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y ((transpose . reverse) l))

where ‘x’ and ‘y’ is the number of colums and rows respectively (maybe can help to do the function).

I try rotate 90° to the left with your anwer and the image result is wrong.

i try

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y ((reverse . transpose) l))

and

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y ((transpose . reverse) l))

and

spin :: PBMfile -> PBMfile
spin (PBM x y l) = (PBM x y (((map reverse) . transpose) l))

to rotate the image but does not work.

the result is something like

http://imageshack.us/photo/my-images/52/catmc.jpg/

  • 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-03T07:00:40+00:00Added an answer on June 3, 2026 at 7:00 am

    TL;DR: transpose . reverse

    If you’re planning to use lists to store large images, bear in mind that it will probably be inefficient, since there’s five boxed values (a lot of bytes) for every pixel. It’d be more efficient to use an unboxed Vector or Array instead. Just giving you a heads up.

    That said, let’s look at list operations in terms of what they do to the image.

    > let demo f = mapM_ print $ f m
    > demo id
    [RGB 1 2 3,RGB 4 5 6]
    [RGB 7 8 9,RGB 1 5 9]
    > demo reverse
    [RGB 7 8 9,RGB 1 5 9]
    [RGB 1 2 3,RGB 4 5 6]
    > demo (map reverse)
    [RGB 4 5 6,RGB 1 2 3]
    [RGB 1 5 9,RGB 7 8 9]
    > demo (transpose)
    [RGB 1 2 3,RGB 7 8 9]
    [RGB 4 5 6,RGB 1 5 9]
    
    • reverse flips the image vertically (by reversing the rows)

    • map reverse flips the image horizontally (by reversing the pixels in each row)

    • transpose flips the image along the \ diagonal line.

    Now, find a piece of paper, and figure out how to perform the desired rotation in terms of these operations (modeling transpose is tricky if your paper is rectangular). Remember that any time you see the back of the paper, the image will appear mirrored. Since each of these operations turns the paper around, you need an even number of them to perform a rotation.

    The only rotation you can do with reverse and map reverse is turn the paper upside down. This means you’ll need transpose to rotate the image 90°.

    transpose (diagonal flip) followed by reverse (vertical flip) rotates the image 90° to the left:

    > demo (reverse . transpose)
    [RGB 4 5 6,RGB 1 5 9]
    [RGB 1 2 3,RGB 7 8 9]
    

    On the other hand, reverse (vertical flip) followed by transpose (diagonal flip) rotates the image 90° to the right (which you want):

    > demo (transpose . reverse)
    [RGB 7 8 9,RGB 1 2 3]
    [RGB 1 5 9,RGB 4 5 6]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help about WCF and authorization. Currently I have a client which
I need some help about RegExp in AS3. I have a simple pattern :
I have one question about Yii framework, and I need your help. Basicly, I
I need help about how to numeration text in file. I have also linux
I need some help about how to dump only database schema, not the data.
I have a CMS script. I need help about title formatting. Example: user defines
I need some help about xsl. I have a date attribute in source xml
I need some help about JavaScript on iPhone UIWebView ; I have HTML like
Need some help about with Memcache. I have created a class and want to
I need to help about writing regex for below string. I have tried lots

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.