diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-12-03 17:37:59 -0700 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-12-03 17:37:59 -0700 |
commit | ba59711a51b4fee34009b1fe6afdce9ef8e60ae0 (patch) | |
tree | 7274bd2c9007abe08c8db7cea9e55babfd041125 /Graphics/Glyph/ArrayGenerator.hs | |
parent | 601f77922490888c3ae9986674e332a5192008ec (diff) | |
download | terralloc-ba59711a51b4fee34009b1fe6afdce9ef8e60ae0.tar.gz terralloc-ba59711a51b4fee34009b1fe6afdce9ef8e60ae0.tar.bz2 terralloc-ba59711a51b4fee34009b1fe6afdce9ef8e60ae0.zip |
Diffstat (limited to 'Graphics/Glyph/ArrayGenerator.hs')
-rw-r--r-- | Graphics/Glyph/ArrayGenerator.hs | 41 |
1 files changed, 22 insertions, 19 deletions
diff --git a/Graphics/Glyph/ArrayGenerator.hs b/Graphics/Glyph/ArrayGenerator.hs index 16fe41f..088ccc7 100644 --- a/Graphics/Glyph/ArrayGenerator.hs +++ b/Graphics/Glyph/ArrayGenerator.hs @@ -1,9 +1,9 @@ {-# LANGUAGE UndecidableInstances #-} -module Graphics.Glyph.ArrayGenerator where -import qualified Data.Map as M +module Graphics.Glyph.ArrayGenerator where import Data.Array +import qualified Data.Map as M import Data.Maybe data ArrayTransaction ix val b = ArrayBuilderM_ (M.Map ix val) b @@ -13,33 +13,36 @@ instance (Ord ix) => Functor (ArrayTransaction ix a) where instance (Ord ix) => Applicative (ArrayTransaction ix a) where (<*>) afn aa = do - fn <- afn - a <- aa - return (fn a) + fn <- afn + a <- aa + return (fn a) pure = return instance (Ord ix) => Monad (ArrayTransaction ix a) where - return = ArrayBuilderM_ M.empty - (ArrayBuilderM_ map1 val) >>= f = - ArrayBuilderM_ (map1 `M.union` map2) val2 - where (ArrayBuilderM_ map2 val2) = f val + return = ArrayBuilderM_ M.empty + (ArrayBuilderM_ map1 val) >>= f = + ArrayBuilderM_ (map1 `M.union` map2) val2 + where + (ArrayBuilderM_ map2 val2) = f val class HasDefault a where - theDefault :: a + theDefault :: a instance (Num a) => HasDefault a where - theDefault = 0 -instance (HasDefault a, HasDefault b) => HasDefault (a,b) where - theDefault = (theDefault,theDefault) -instance (HasDefault a, HasDefault b, HasDefault c) => HasDefault (a,b,c) where - theDefault = (theDefault,theDefault,theDefault) + theDefault = 0 + +instance (HasDefault a, HasDefault b) => HasDefault (a, b) where + theDefault = (theDefault, theDefault) + +instance (HasDefault a, HasDefault b, HasDefault c) => HasDefault (a, b, c) where + theDefault = (theDefault, theDefault, theDefault) writeArray :: ix -> a -> ArrayTransaction ix a () writeArray index' val = ArrayBuilderM_ (M.singleton index' val) () -buildArray :: (Ix ix) => (ix,ix) -> e -> ArrayTransaction ix e () -> Array ix e +buildArray :: (Ix ix) => (ix, ix) -> e -> ArrayTransaction ix e () -> Array ix e buildArray bounds' def (ArrayBuilderM_ map' _) = - listArray bounds' [maybeLookup map' bound | bound <- range bounds'] - where maybeLookup map_ key = fromMaybe def (M.lookup key map_) - + listArray bounds' [maybeLookup map' bound | bound <- range bounds'] + where + maybeLookup map_ key = fromMaybe def (M.lookup key map_) |