Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

matrix display error #60

Open
acapi opened this issue Nov 21, 2018 · 3 comments
Open

matrix display error #60

acapi opened this issue Nov 21, 2018 · 3 comments
Assignees

Comments

@acapi
Copy link

acapi commented Nov 21, 2018

It is not possible to correctly display an array in WinGHCi.

prettyMatrix $ matrix 4 4 $ \(i,j) -> 2*i - j

"\9484 \9488\n\9474 1 0 -1 -2 \9474\n\9474 3 2 1 0 \9474\n\9474 5 4 3 2 \9474\n\9474 7 6 5 4 \9474\n\9492 \9496"
it :: String
(0.00 secs, 193,072 bytes)

putStrLn it
*** Exception: : hPutChar: invalid argument (invalid character)


It's all OK if:

putStrLn $ filter (notElem ['\9488','\9474','\9484','\9492','\9496'] ) $ prettyMatrix $ matrix 4 4 $ \(i,j) -> 2*i - j

1 0 -1 -2
3 2 1 0
5 4 3 2
7 6 5 4

@wchresta
Copy link
Contributor

This is probably an issue with your terminal/stdout not being set up to support unicode characters. This is more an issue of the environment; although I think that using unicode characters in the show instance instead of the more compatible ascii alternative should be avoided.

c.f. https://stackoverflow.com/questions/28003875/haskell-save-unicode-string-characters-to-file

@acapi
Copy link
Author

acapi commented Apr 25, 2019

Now I use this pretty function:

import qualified Data.Map as M

prettyMatrixASCII = putStrLn . f . prettyMatrix
    where
    f xs = map (\x -> case M.lookup x conv of
                        Nothing -> x
                        Just y  -> y) xs
        where
        conv = M.fromList [('\9488','\\'),('\9474','|'),('\9484','/'),('\9492','\\'),('\9496','/')]

With results similar to the original function:

/             \
|  1  0 -1 -2 |
|  3  2  1  0 |
|  5  4  3  2 |
|  7  6  5  4 |
\             /

However it is very inconvenient to have to repopulate this function in every module that uses Data.Matrix.

Could you insert in the library a function similar to mine?

@Daniel-Diaz Daniel-Diaz self-assigned this Apr 25, 2019
@Daniel-Diaz
Copy link
Owner

Thanks for pinging again and providing some code. I will get this fixed over the weekend.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants