Skip to content

Commit

Permalink
Remove @? (#3216)
Browse files Browse the repository at this point in the history
* Closes #3210
  • Loading branch information
lukaszcz authored Dec 4, 2024
1 parent 70cbdd0 commit 021fc0c
Show file tree
Hide file tree
Showing 97 changed files with 261 additions and 315 deletions.
2 changes: 1 addition & 1 deletion examples/demo/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "Demo";
version := mkVersion 0 1 0
};
2 changes: 1 addition & 1 deletion examples/midsquare/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "midsquare";
version := mkVersion 0 1 0
};
2 changes: 1 addition & 1 deletion examples/milestone/Bank/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "bank"
};
2 changes: 1 addition & 1 deletion examples/milestone/Collatz/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "Collatz";
version := mkVersion 0 1 0;
main := just "Collatz.juvix"
Expand Down
2 changes: 1 addition & 1 deletion examples/milestone/Fibonacci/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "Fibonacci";
version := mkVersion 0 1 0;
main := just "Fibonacci.juvix"
Expand Down
2 changes: 1 addition & 1 deletion examples/milestone/Hanoi/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "Hanoi";
version := mkVersion 0 1 0;
main := just "Hanoi.juvix"
Expand Down
2 changes: 1 addition & 1 deletion examples/milestone/HelloWorld/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "HelloWorld";
version := mkVersion 0 1 0;
main := just "HelloWorld.juvix"
Expand Down
2 changes: 1 addition & 1 deletion examples/milestone/PascalsTriangle/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "PascalsTriangle";
version := mkVersion 0 1 0;
main := just "PascalsTriangle.juvix"
Expand Down
2 changes: 1 addition & 1 deletion examples/milestone/TicTacToe/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "TicTacToe";
version := mkVersion 0 1 0;
main := just "CLI/TicTacToe.juvix"
Expand Down
2 changes: 1 addition & 1 deletion examples/milestone/Tutorial/Package.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Package;
import PackageDescription.V2 open;

package : Package :=
defaultPackage@?{
defaultPackage@{
name := "Tutorial";
version := mkVersion 0 1 0
};
2 changes: 1 addition & 1 deletion include/package/PackageDescription/V1.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mkVersion
{release : Maybe String := nothing}
{meta : Maybe String := nothing}
: SemVer :=
mkSemVer@?{
mkSemVer@{
major;
minor;
patch;
Expand Down
2 changes: 1 addition & 1 deletion include/package/PackageDescription/V2.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mkVersion
{release : Maybe String := nothing}
{meta : Maybe String := nothing}
: SemVer :=
mkSemVer@?{
mkSemVer@{
major;
minor;
patch;
Expand Down
2 changes: 1 addition & 1 deletion juvix-stdlib
36 changes: 7 additions & 29 deletions src/Juvix/Compiler/Concrete/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,6 @@ smallUniverseExpression = do
_expressionAtoms = pure (AtomUniverse (smallUniverse loc))
}

isExhaustive :: (Member (Reader Interval) r) => Bool -> Sem r IsExhaustive
isExhaustive _isExhaustive = do
_isExhaustiveKw <-
Irrelevant
<$> if
| _isExhaustive -> kw kwAt
| otherwise -> kw kwAtQuestion

return IsExhaustive {..}

symbol :: (Member (Reader Interval) r) => Text -> Sem r Symbol
symbol t = do
l <- ask
Expand Down Expand Up @@ -107,25 +97,13 @@ braced a = do
l <- ask
AtomBraces . WithLoc l <$> expressionAtoms' a

mkIsExhaustive :: (Member (Reader Interval) r) => Bool -> Sem r IsExhaustive
mkIsExhaustive _isExhaustive = do
keyw <-
if
| _isExhaustive -> kw kwAt
| otherwise -> kw kwAtQuestion
return
IsExhaustive
{ _isExhaustiveKw = Irrelevant keyw,
_isExhaustive
}

namedApplication :: Name -> IsExhaustive -> [NamedArgumentNew 'Parsed] -> ExpressionAtom 'Parsed
namedApplication n exh as =
AtomNamedApplicationNew
NamedApplicationNew
{ _namedApplicationNewName = n,
_namedApplicationNewExhaustive = exh,
_namedApplicationNewArguments = as
namedApplication :: Name -> Irrelevant KeywordRef -> [NamedArgument 'Parsed] -> ExpressionAtom 'Parsed
namedApplication n kwd as =
AtomNamedApplication
NamedApplication
{ _namedApplicationName = n,
_namedApplicationAtKw = kwd,
_namedApplicationArguments = as
}

literalInteger :: (Member (Reader Interval) r, Integral a) => a -> Sem r (ExpressionAtom 'Parsed)
Expand Down
2 changes: 0 additions & 2 deletions src/Juvix/Compiler/Concrete/Keywords.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Juvix.Data.Keyword.All
kwAssign,
kwAssoc,
kwAt,
kwAtQuestion,
kwAxiom,
kwBelow,
kwBinary,
Expand Down Expand Up @@ -88,7 +87,6 @@ reservedKeywords =
kwAssign,
kwDeriving,
kwAt,
kwAtQuestion,
kwAxiom,
kwCase,
kwColon,
Expand Down
103 changes: 46 additions & 57 deletions src/Juvix/Compiler/Concrete/Language/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,7 @@ data Expression
| ExpressionBraces (WithLoc Expression)
| ExpressionDoubleBraces (DoubleBracesExpression 'Scoped)
| ExpressionIterator (Iterator 'Scoped)
| ExpressionNamedApplicationNew (NamedApplicationNew 'Scoped)
| ExpressionNamedApplication (NamedApplication 'Scoped)
deriving stock (Show, Eq, Ord, Generic)

instance Serialize Expression
Expand Down Expand Up @@ -2537,67 +2537,57 @@ deriving stock instance Ord (NamedArgumentPun 'Parsed)

deriving stock instance Ord (NamedArgumentPun 'Scoped)

data NamedArgumentNew (s :: Stage)
= NamedArgumentNewFunction (NamedArgumentFunctionDef s)
data NamedArgument (s :: Stage)
= NamedArgumentFunction (NamedArgumentFunctionDef s)
| NamedArgumentItemPun (NamedArgumentPun s)
deriving stock (Generic)

instance Serialize (NamedArgumentNew 'Scoped)
instance Serialize (NamedArgument 'Scoped)

instance NFData (NamedArgumentNew 'Scoped)
instance NFData (NamedArgument 'Scoped)

instance Serialize (NamedArgumentNew 'Parsed)
instance Serialize (NamedArgument 'Parsed)

instance NFData (NamedArgumentNew 'Parsed)
instance NFData (NamedArgument 'Parsed)

deriving stock instance Show (NamedArgumentNew 'Parsed)
deriving stock instance Show (NamedArgument 'Parsed)

deriving stock instance Show (NamedArgumentNew 'Scoped)
deriving stock instance Show (NamedArgument 'Scoped)

deriving stock instance Eq (NamedArgumentNew 'Parsed)
deriving stock instance Eq (NamedArgument 'Parsed)

deriving stock instance Eq (NamedArgumentNew 'Scoped)
deriving stock instance Eq (NamedArgument 'Scoped)

deriving stock instance Ord (NamedArgumentNew 'Parsed)
deriving stock instance Ord (NamedArgument 'Parsed)

deriving stock instance Ord (NamedArgumentNew 'Scoped)
deriving stock instance Ord (NamedArgument 'Scoped)

data IsExhaustive = IsExhaustive
{ _isExhaustive :: Bool,
_isExhaustiveKw :: Irrelevant KeywordRef
}
deriving stock (Eq, Show, Ord, Generic)

instance Serialize IsExhaustive

instance NFData IsExhaustive

data NamedApplicationNew (s :: Stage) = NamedApplicationNew
{ _namedApplicationNewName :: IdentifierType s,
_namedApplicationNewExhaustive :: IsExhaustive,
_namedApplicationNewArguments :: [NamedArgumentNew s]
data NamedApplication (s :: Stage) = NamedApplication
{ _namedApplicationName :: IdentifierType s,
_namedApplicationAtKw :: Irrelevant KeywordRef,
_namedApplicationArguments :: [NamedArgument s]
}
deriving stock (Generic)

instance Serialize (NamedApplicationNew 'Scoped)
instance Serialize (NamedApplication 'Scoped)

instance NFData (NamedApplicationNew 'Scoped)
instance NFData (NamedApplication 'Scoped)

instance Serialize (NamedApplicationNew 'Parsed)
instance Serialize (NamedApplication 'Parsed)

instance NFData (NamedApplicationNew 'Parsed)
instance NFData (NamedApplication 'Parsed)

deriving stock instance Show (NamedApplicationNew 'Parsed)
deriving stock instance Show (NamedApplication 'Parsed)

deriving stock instance Show (NamedApplicationNew 'Scoped)
deriving stock instance Show (NamedApplication 'Scoped)

deriving stock instance Eq (NamedApplicationNew 'Parsed)
deriving stock instance Eq (NamedApplication 'Parsed)

deriving stock instance Eq (NamedApplicationNew 'Scoped)
deriving stock instance Eq (NamedApplication 'Scoped)

deriving stock instance Ord (NamedApplicationNew 'Parsed)
deriving stock instance Ord (NamedApplication 'Parsed)

deriving stock instance Ord (NamedApplicationNew 'Scoped)
deriving stock instance Ord (NamedApplication 'Scoped)

data RecordSyntaxDef (s :: Stage)
= RecordSyntaxOperator (OperatorSyntaxDef s)
Expand Down Expand Up @@ -2741,7 +2731,7 @@ data ExpressionAtom (s :: Stage)
| AtomLiteral LiteralLoc
| AtomParens (ExpressionType s)
| AtomIterator (Iterator s)
| AtomNamedApplicationNew (NamedApplicationNew s)
| AtomNamedApplication (NamedApplication s)
deriving stock (Generic)

instance Serialize (ExpressionAtom 'Parsed)
Expand Down Expand Up @@ -3000,7 +2990,6 @@ makeLenses ''FunctionLhs
makeLenses ''Statements
makeLenses ''NamedArgumentFunctionDef
makeLenses ''NamedArgumentPun
makeLenses ''IsExhaustive
makeLenses ''SideIfBranch
makeLenses ''RhsExpression
makeLenses ''PatternArg
Expand Down Expand Up @@ -3069,8 +3058,8 @@ makeLenses ''Initializer
makeLenses ''Range
makeLenses ''ArgumentBlock
makeLenses ''NamedArgumentAssign
makeLenses ''NamedArgumentNew
makeLenses ''NamedApplicationNew
makeLenses ''NamedArgument
makeLenses ''NamedApplication
makeLenses ''AliasDef
makeLenses ''FixitySyntaxDef
makeLenses ''ParsedFixityInfo
Expand All @@ -3083,7 +3072,7 @@ makeLenses ''RecordInfo
makeLenses ''MarkdownInfo
makeLenses ''Deriving

makePrisms ''NamedArgumentNew
makePrisms ''NamedArgument
makePrisms ''ConstructorRhs
makePrisms ''FunctionDefNameParsed

Expand Down Expand Up @@ -3176,7 +3165,7 @@ instance (SingI s) => HasLoc (ArgumentBlock s) where
instance HasAtomicity (ArgumentBlock s) where
atomicity = const Atom

instance HasAtomicity (NamedApplicationNew s) where
instance HasAtomicity (NamedApplication s) where
atomicity = const (Aggregate updateFixity)

instance HasAtomicity (Do s) where
Expand All @@ -3203,7 +3192,7 @@ instance HasAtomicity Expression where
ExpressionCase c -> atomicity c
ExpressionIf x -> atomicity x
ExpressionIterator i -> atomicity i
ExpressionNamedApplicationNew i -> atomicity i
ExpressionNamedApplication i -> atomicity i
ExpressionRecordUpdate {} -> Aggregate updateFixity
ExpressionParensRecordUpdate {} -> Atom

Expand Down Expand Up @@ -3414,9 +3403,9 @@ instance HasLoc (List s) where
instance (SingI s) => HasLoc (NamedArgumentFunctionDef s) where
getLoc (NamedArgumentFunctionDef f) = getLoc f

instance (SingI s) => HasLoc (NamedArgumentNew s) where
instance (SingI s) => HasLoc (NamedArgument s) where
getLoc = \case
NamedArgumentNewFunction f -> getLoc f
NamedArgumentFunction f -> getLoc f
NamedArgumentItemPun f -> getLoc f

instance HasLoc (RecordUpdatePun s) where
Expand All @@ -3425,8 +3414,8 @@ instance HasLoc (RecordUpdatePun s) where
instance HasLoc (NamedArgumentPun s) where
getLoc NamedArgumentPun {..} = getLocSymbolType _namedArgumentPunSymbol

instance (SingI s) => HasLoc (NamedApplicationNew s) where
getLoc NamedApplicationNew {..} = getLocIdentifierType _namedApplicationNewName
instance (SingI s) => HasLoc (NamedApplication s) where
getLoc NamedApplication {..} = getLocIdentifierType _namedApplicationName

instance (SingI s) => HasLoc (RecordUpdateField s) where
getLoc = \case
Expand Down Expand Up @@ -3478,7 +3467,7 @@ instance HasLoc Expression where
ExpressionBraces i -> getLoc i
ExpressionDoubleBraces i -> getLoc i
ExpressionIterator i -> getLoc i
ExpressionNamedApplicationNew i -> getLoc i
ExpressionNamedApplication i -> getLoc i
ExpressionRecordUpdate i -> getLoc i
ExpressionParensRecordUpdate i -> getLoc i

Expand Down Expand Up @@ -3707,7 +3696,7 @@ instance (SingI s) => HasLoc (ExpressionAtom s) where
AtomLiteral x -> getLoc x
AtomParens x -> getLocExpressionType x
AtomIterator x -> getLoc x
AtomNamedApplicationNew x -> getLoc x
AtomNamedApplication x -> getLoc x

instance HasLoc (ExpressionAtoms s) where
getLoc = getLoc . (^. expressionAtomsLoc)
Expand Down Expand Up @@ -3769,17 +3758,17 @@ withFunctionSymbol a f sym = case sing :: SStage s of
SParsed -> maybe a f (sym ^? _FunctionDefName)
SScoped -> f (sym ^. functionDefNameScoped)

namedArgumentNewSymbolParsed :: (SingI s) => SimpleGetter (NamedArgumentNew s) Symbol
namedArgumentNewSymbolParsed = to $ \case
namedArgumentSymbolParsed :: (SingI s) => SimpleGetter (NamedArgument s) Symbol
namedArgumentSymbolParsed = to $ \case
NamedArgumentItemPun a -> a ^. namedArgumentPunSymbol
NamedArgumentNewFunction a -> symbolParsed (getFunctionSymbol (a ^. namedArgumentFunctionDef . functionDefName))
NamedArgumentFunction a -> symbolParsed (getFunctionSymbol (a ^. namedArgumentFunctionDef . functionDefName))

namedArgumentNewSymbol :: Lens' (NamedArgumentNew 'Parsed) Symbol
namedArgumentNewSymbol f = \case
namedArgumentSymbol :: Lens' (NamedArgument 'Parsed) Symbol
namedArgumentSymbol f = \case
NamedArgumentItemPun a -> NamedArgumentItemPun <$> (namedArgumentPunSymbol f a)
NamedArgumentNewFunction a -> do
NamedArgumentFunction a -> do
a' <- f (a ^?! namedArgumentFunctionDef . functionDefName . _FunctionDefName)
return $ NamedArgumentNewFunction (over namedArgumentFunctionDef (set functionDefName (FunctionDefName a')) a)
return $ NamedArgumentFunction (over namedArgumentFunctionDef (set functionDefName (FunctionDefName a')) a)

scopedIdenSrcName :: Lens' ScopedIden S.Name
scopedIdenSrcName f n = case n ^. scopedIdenAlias of
Expand Down
Loading

0 comments on commit 021fc0c

Please sign in to comment.