{-# OPTIONS -fallow-overlapping-instances #-}

module Autolib.Util.Bild 

( Bild 
, ToBild (..)
, module Data.Array
)

where

import Data.Array

import Autolib.ToDoc

type Bild = Array (Int, Int) Char

instance ToDoc Bild where
    toDocPrec :: Int -> Bild -> Doc
toDocPrec Int
_ Bild
b = [Doc] -> Doc
vcat ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ do
	let ((Int
l,Int
u),(Int
r,Int
o)) = Bild -> ((Int, Int), (Int, Int))
forall i e. Array i e -> (i, i)
bounds Bild
b
	y <- [Int] -> [Int]
forall a. [a] -> [a]
reverse [ Int
u .. Int
o ]
	return $ text $ do
	    x <- [ l ..  r ]
	    return $ b ! (x,y)

class ToBild a where
      toBild :: a -> Bild