@@ -3,8 +3,8 @@ module Output.Haskell where
33import Prelude
44
55import Control.Monad.Free (Free , liftF , wrap )
6- import Data.Array (intercalate , singleton , replicate , uncons )
7- import Data.Foldable (foldMap , foldl , length )
6+ import Data.Array (intercalate , singleton , replicate , uncons , unsnoc )
7+ import Data.Foldable (foldMap , foldr , length )
88import Data.FoldableWithIndex (foldMapWithIndex )
99import Data.Map as Map
1010import Data.Maybe (maybe )
@@ -55,7 +55,7 @@ haskellCode' = foldFix \(Ann _ f) -> alg f where
5555 , code: toLower bid }
5656 Cup -> { i: liftF [] , o: liftF [" a0" , " a1" ], code: " cup" }
5757 Cap -> { i: liftF [" a0" , " a1" ], o: liftF [] , code: " cap" }
58- alg (TC ts) = ts # uncons # maybe haskellEmpty (\{ head, tail } -> foldl compose head tail ) # mapCode braced
58+ alg (TC ts) = ts # unsnoc # maybe haskellEmpty (\{ init, last } -> foldr compose last init ) # mapCode braced
5959 where
6060 compose l r = { i: l.i, o: r.o, code : l.code `comp` arr (showNested l.o) (showNested i') `comp` r.code }
6161 where
@@ -65,11 +65,11 @@ haskellCode' = foldFix \(Ann _ f) -> alg f where
6565 alg (TT ts) = foldMapWithIndex f ts # g
6666 where
6767 f j { i, o, code } = [{ i: map (\n -> n <> " _" <> show j) i, o: map (\n -> n <> " _" <> show j) o, code }]
68- g l = uncons l # maybe haskellEmpty (\{ head, tail } -> foldl tensor head tail )
68+ g l = unsnoc l # maybe haskellEmpty (\{ init, last } -> foldr tensor last init )
6969 tensor l r =
7070 { i: wrap [l.i, r.i]
7171 , o: wrap [l.o, r.o]
72- , code: braced ( l.code <> " *** " <> r.code)
72+ , code: l.code <> " *** " <> r.code
7373 }
7474
7575mapCode :: (String -> String ) -> HaskellCode -> HaskellCode
0 commit comments