Haskell converts a list of points to a string

I am working on a task and I need help. This is the last part, but I really struggle with it, I don’t know how to approach. Here's the problem:

Add a render function that accepts the image and returns a string that, if printed, would give a schematic representation of the image as shown below (make sure that one border is all sides of the image). As an example, render t should return

".|...\n.xxx.\n-+x--\n.|...\n"

(where the points in the image are indicated by "x", the origin is indicated by '+', and the horizontal and vertical axes are indicated by '-' and '|', respectively):

.|...
.xxx.
-+x--
.|...

(The line we create with the render t function can be printed using putStr (rendering t) to achieve the above result).

image and t are only:

type Point = (Int,Int)
type Image = [Point]
t :: Image
t=[(0,1),(1,0),(1,1),(2,1)]

, , . , max/min y x, , . , n .

+4
2

, :

dimensions :: Image -> (Point, Point)

. :

sortImage :: Image -> Image

y x (: Data.List.sortBy - ). , . (.. '.', )

blankImage :: (Point, Point) -> [String]

. , , . [String] = [[Char]], 2D . Point , , (0, 0). , . , dimensions.

, blankImage , Image. Point blankImage, .

fillImage :: Image -> [String] -> [String]

, :

import Data.List

showImage :: Image -> String
showImage img = intercalate "\n" filled
    where
        sortedImg = sorteImage img
        (upperL, lowerR) = dimensions sortedImg
        blank = blankImage (upperL, lowerR)
        offsetImg = offsetImage upperL sortedImg
        filled = fillImage offsetImg blank
    putStrLn $ intercalate "\n" filled

intercalate [String] , .


, Haskell, , , , . , , , .

+6

:

  • , ? , , . . , type, FImage. , (, ).
  • , FImage. , . ?
  • , FImage Point, FImage x .
  • . , : ?
  • FImage , String. , List List.
  • . ! . ( ). Haskell , foldl foldr, ( ).
  • : -)

!

( .)

0

All Articles