~jojo/Carth

ee429e8ba7a4b52a7f638a89e8ca27a92e0c16dd — JoJo a month ago 12cf2a6
Remove unused definitions

No big ones. Mostly small stuff that might be convenient at some point
actually, but I'll just find them or rewrite them then. Shouldn't keep
unused code in the codebase, pretty much regardless of potential. We
use git for a reason.
6 files changed, 41 insertions(+), 41 deletions(-)

M TODO.org
M src/Gen.hs
M src/Low.hs
M src/Misc.hs
M src/Parser.hs
M src/TypeAst.hs
M TODO.org => TODO.org +41 -0
@@ 1061,3 1061,44 @@ Features and other stuff to do/implement in/around Carth.
  and that might be achievable with some more general and cleaner
  method. Some kind of shadow stack, for example. Such a method might
  work well for other potential backends as well, like a C backend.

* INACTIVE Add kind of ~apply~ function that takes tuple
  #+BEGIN_SRC carth
  (define (foo a b c)
    (+ a (* b c)))

  (assert-eq (foo 1 2 3) (apply foo [1 2 3]))
  (assert-eq (foo 1 2) (apply foo [1 2]))
  #+END_SRC

  In general, ~(apply f [x1 ... xn])~ becomes ~(f x1 ... xn)~.

  I think it could be a function, via a type class instance that
  recurses on the pairs of a tuple.

  One usage that could be nice in particular is when you want to apply
  a function with "default" arguments. You could then do ~(apply f
  default)~ instead of anything more complex.

  Then again, you can do something arguably more convenient with
  typeclasses and deriving in haskell. Create a record for the
  specific argument set, derive Default, and call it like ~f (default
  {foo = 3})~.
  
* INACTIVE SoA record attribute
  https://blog.royalsloth.eu/posts/the-compiler-will-optimize-that-away/

  Convenient syntax for using SoA/AoS could be nice for lowe level
  stuff, or we might consider it too seldom an issue for a somewhat
  high-level languge like Carth.
* INACTIVE Recursion schemes
  Recursion schemes are functions that capture patterns of recursion,
  like fold and unfold. These 2 are simple to implement. Other
  schemes, less commonly used yet frequently applicable, like cata,
  could be implemented as well, but might require some built in
  support or smart "deriving".

  Look at https://hackage.haskell.org/package/recursion-schemes-5.2.2.1

  Maybe deriving functor and/or foldable could include this base
  functor thingy?

M src/Gen.hs => src/Gen.hs +0 -3
@@ 1082,9 1082,6 @@ litU32 = ConstantOperand . LLConst.Int 32 . toInteger
litI8' :: Integral n => n -> LLConst.Constant
litI8' = LLConst.Int 8 . toInteger

litDouble :: Double -> Operand
litDouble = ConstantOperand . LLConst.Float . LLFloat.Double

litStruct :: [LLConst.Constant] -> LLConst.Constant
litStruct = LLConst.Struct Nothing False


M src/Low.hs => src/Low.hs +0 -3
@@ 86,9 86,6 @@ instance FreeVars Expr TypedVar where
instance FreeVars Expr' TypedVar where
    freeVars = fvExpr'

expr' :: Expr -> Expr'
expr' (Expr _ e) = e

fvExpr' :: Expr' -> Set TypedVar
fvExpr' = \case
    Lit _ -> Set.empty

M src/Misc.hs => src/Misc.hs +0 -20
@@ 41,12 41,6 @@ precalate prefix = \case
indent :: Int -> String
indent = flip replicate ' '

both :: (a -> b) -> (a, a) -> (b, b)
both f (a0, a1) = (f a0, f a1)

firstM :: (Bitraversable t, Applicative f) => (a -> f a') -> t a b -> f (t a' b)
firstM = flip bimapM pure

secondM :: (Bitraversable t, Applicative f) => (b -> f b') -> t a b -> f (t a b')
secondM = bimapM pure



@@ 72,10 66,6 @@ scribe l b = tell (set l b mempty)
(.*) = (.) . (.)
infixr 8 .*

(.**) :: (d -> e) -> (a -> b -> c -> d) -> a -> b -> c -> e
(.**) = (.) . (.*)
infixr 8 .**

abort :: FilePath -> IO a
abort f = do
    putStrLn "Error: Aborting due to previous error."


@@ 112,16 102,6 @@ unsnoc = \case
        Just (ys, y) -> Just (x : ys, y)
        Nothing -> Just ([], x)

is2tup :: [a] -> Maybe (a, a)
is2tup = \case
    a1 : [a2] -> Just (a1, a2)
    _ -> Nothing

is3tup :: [a] -> Maybe (a, a, a)
is3tup = \case
    a1 : a2 : [a3] -> Just (a1, a2, a3)
    _ -> Nothing

takeWhileJust :: (a -> Maybe b) -> [a] -> [b]
takeWhileJust f = \case
    [] -> []

M src/Parser.hs => src/Parser.hs +0 -3
@@ 131,9 131,6 @@ sexpr expected extract f = do
    modify (\st -> st { stOuterPos = pOld, stInput = ttsOld })
    pure a

big' :: Parser String
big' = fmap idstr big

big :: Parser (Id 'Parsed.Big)
big = token "big identifier" $ \p -> \case
    Lexd.Big x -> Just (Id (WithPos p x))

M src/TypeAst.hs => src/TypeAst.hs +0 -12
@@ 36,24 36,12 @@ tByte = tprim (TNat 8)
tBox' :: t -> TConst t
tBox' t = ("Box", [t])

tStr :: TypeAst t => t
tStr = tconst tStr'

tStr' :: TConst t
tStr' = ("Str", [])

tArray :: TypeAst t => t -> t
tArray a = tconst ("Array", [a])

tTuple :: TypeAst t => [t] -> t
tTuple = foldr tCons tUnit

tCons :: TypeAst t => t -> t -> t
tCons car cdr = tconst ("Cons", [car, cdr])

tRealWorld :: TypeAst t => t
tRealWorld = tconst ("RealWorld", [])

tUnit :: TypeAst t => t
tUnit = tconst tUnit'