Skip to content

Commit

Permalink
etc
Browse files Browse the repository at this point in the history
  • Loading branch information
ejconlon committed Feb 13, 2024
1 parent be07162 commit c795248
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
6 changes: 5 additions & 1 deletion minipat/src/Minipat/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,11 @@ instance Pretty Factor where

-- | Make a 'Factor' representing the given 'Rational'
factorFromRational :: Rational -> Factor
factorFromRational = FactorRational RationalPresDec
factorFromRational f =
let (q, r) = quotRem (numerator f) (denominator f)
in if r == 0
then FactorInteger q
else FactorRational RationalPresDec f

factorUnary :: (forall a. (Num a) => a -> a) -> Factor -> Factor
factorUnary f = \case
Expand Down
6 changes: 3 additions & 3 deletions minipat/src/Minipat/Pattern.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mkPatGroup :: GroupType -> Seq (Pat b a) -> Reader b (Pat b a)
mkPatGroup gt = \case
Empty -> mkPat PatSilence
x :<| Empty -> pure x
xs -> mkPat (PatGroup (Group 0 gt (fmap unPat xs)))
xs -> mkPat (PatGroup (Group 1 gt (fmap unPat xs)))

mkPatMod :: ModType b -> Pat b a -> Reader b (Pat b a)
mkPatMod mt (Pat pa) = mkPat (PatMod (Mod pa mt))
Expand All @@ -54,8 +54,8 @@ mkPatSeq = \case
(x, _) :<| Empty -> pure x
xs ->
let w = sum (fmap snd (toList xs))
adjust (x, t) = unPat (patFastBy (t / w) x)
in mkPat (PatGroup (Group 0 (GroupTypeSeq SeqPresSpace) (fmap adjust xs)))
adjust (x, _) = unPat x
in mkPat (PatGroup (Group 1 (GroupTypeSeq SeqPresSpace) (fmap adjust xs)))

-- | 'Pat' and 'Stream' can be constructed abstractly with this
class (Functor f, Monad (PatM f), Default (PatA f)) => Pattern f where
Expand Down
32 changes: 28 additions & 4 deletions minipat/test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -705,9 +705,33 @@ testPatReprCases =
, Nothing
)
,
( "seq"
( "seq 1"
, "[x]"
, Just (mkTPat (PatPure "x"))
, Just "x"
)
,
( "seq 2"
, "[x y]"
, Nothing -- Just (mkTPat (PatPure "x"))
, Nothing
, Nothing
)
,
( "fast"
, "x*2"
, Nothing
, Nothing
)
,
( "slow"
, "x/2"
, Nothing
, Nothing
)
,
( "seq fast"
, "[x*2 y]"
, Nothing
, Nothing
)
]
Expand Down Expand Up @@ -739,7 +763,7 @@ main = do
[ testParseCases
, testPatNormCases
, testPatInterpCases
-- TODO fix these
, testPatReprCases
-- TODO fix this
-- , testUr
-- , testPatReprCases
]

0 comments on commit c795248

Please sign in to comment.