Skip to content

Commit

Permalink
Introduce a version of intercalate on Foldables instead of List. #71
Browse files Browse the repository at this point in the history
  • Loading branch information
epost committed Oct 15, 2018
1 parent 9ac4626 commit f34f8df
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 8 deletions.
11 changes: 10 additions & 1 deletion src/Language/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
,LiberalTypeSynonyms, ImpredicativeTypes, UndecidableInstances, FunctionalDependencies #-}

module Language.Common where
import Data.Map.Strict as Map
import Data.Map.Strict as Map hiding (foldl)
import Data.Foldable (foldl)

type a + b = Either a b

Expand Down Expand Up @@ -30,3 +31,11 @@ lookup2 :: Ord k => k -> Map k a -> a
lookup2 m x = case Map.lookup m x of
Just y -> y
Nothing -> undefined

-- | A version of intercalate that works on Foldables instead of just List,
-- | adapted from PureScript.
intercalate :: (Foldable f, Monoid m) => m -> f m -> m
intercalate sep xs = snd (foldl go (True, mempty) xs)
where
go (True, _) x = (False, x)
go (_ , acc) x = (False, acc <> sep <> x)
2 changes: 1 addition & 1 deletion src/Language/Instance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Language.Instance where
import Prelude hiding (EQ)
import Data.Set as Set
import Data.Map.Strict as Map
import Data.List
import Data.List hiding (intercalate)
import Language.Common
import Language.Term as Term
import Language.Typeside as Typeside
Expand Down
1 change: 0 additions & 1 deletion src/Language/Mapping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Language.Common
import Data.Typeable
import Data.Set as Set
import Data.Maybe
import Data.List



Expand Down
1 change: 0 additions & 1 deletion src/Language/Program.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Language.Mapping as M
import Language.Typeside as T
import Language.Transform as Tr
import Language.Query as Q
import Data.List (intercalate)


data Exp =
Expand Down
1 change: 0 additions & 1 deletion src/Language/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Language.Typeside
import Language.Options
import Language.Prover
import Data.Typeable
import Data.List (intercalate)
import Data.Maybe


Expand Down
1 change: 0 additions & 1 deletion src/Language/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Prelude hiding (EQ)
import Data.Set as Set hiding (size, foldr)
import Data.Map.Strict as Map hiding (size, foldr)
import Data.Void
import Data.List (intercalate)
import Language.Common
import Data.Maybe

Expand Down
1 change: 0 additions & 1 deletion src/Language/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Data.Void
import Language.Schema as S
import Data.Typeable
import Data.Maybe
import Data.List
import Language.Options

evalSigmaTrans
Expand Down
1 change: 0 additions & 1 deletion src/Language/Typeside.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Data.Void
import Language.Prover
import Language.Options
import Data.Typeable
import Data.List (intercalate)

fromList'' :: (Show k, Ord k) => [k] -> Err (Set k)
fromList'' (k:l) = do l' <- fromList'' l
Expand Down

0 comments on commit f34f8df

Please sign in to comment.