Skip to content

Commit

Permalink
Upgrade to last GHC currently available in Stack
Browse files Browse the repository at this point in the history
  • Loading branch information
nionita committed Oct 31, 2020
1 parent a5ffd72 commit 090e54f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 3 additions & 2 deletions Moves/Notation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import Moves.Board
toNiceNotation :: MyPos -> Move -> String
toNiceNotation p m
| moveIsCastle m = if s > d then "0-0-0" else "0-0"
| otherwise = piece ++ src ++ capt ++ dst ++ transf ++ chk
| otherwise = piece ++ src ++ capt ++ dst ++ promo ++ chk
where piece = pcToCh False fig
s = fromSquare m
d = toSquare m
(sr, sc) = s `divMod` 8
(dr, dc) = d `divMod` 8
(fig, fcol) | Busy c f <- tabla p s = (f, c)
| otherwise = error "Move nothing"
iscapt | Busy _ _ <- tabla p d = True
| otherwise = False
capt = if iscapt then "x" else ""
Expand All @@ -33,7 +34,7 @@ toNiceNotation p m
| fig == Queen = desamb (queens p)
| otherwise = "" -- king
dst = col dc : row dr : ""
transf = if moveIsPromo m then pcToCh False (movePromoPiece m) else ""
promo = if moveIsPromo m then pcToCh False (movePromoPiece m) else ""
p' = doFromToMove m p
chk = if isCheck p' (other fcol) then "+" else ""
orda = ord 'a'
Expand Down
21 changes: 13 additions & 8 deletions Struct/Params.hs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ data Phase = Mid | End
-- The type class, for which we want to generate an instance for any of our parameter data types
collectParams :: Type
collectParams = ConT $ mkName "CollectParams"
-- We need to derive the Show instance
derivingShow :: DerivClause
derivingShow = DerivClause Nothing [ConT ''Show]

-- This will generate a function to assign a value to a filed of the parameter data type
-- For parameters (one value), this will be: \v rec -> rec { field = round v }
Expand Down Expand Up @@ -166,7 +169,7 @@ evalParams :: Name
evalParams = mkName "EvalParams"

genRecFieldDecP :: String -> VarStrictType
genRecFieldDecP fld = (fldName, IsStrict, ConT ''Int)
genRecFieldDecP fld = (fldName, Bang NoSourceUnpackedness SourceStrict, ConT ''Int)
where fldName = mkName fld

genRecFieldIniP :: EvalParamSpec -> FieldExp
Expand All @@ -179,20 +182,21 @@ genEvalParams = do
bodyExp <- genCollectEvalParamsExp (map fst params) False
let colParm = ValD (VarP $ mkName "npColParm") (NormalB bodyExp) []
theInst = ConT evalParams
typeDec = TySynInstD (mkName "CollectFor") (TySynEqn [theInst] theInst)
collectFor = AppT (ConT (mkName "CollectFor")) theInst
typeDec = TySynInstD (TySynEqn Nothing collectFor theInst)
colInit = ValD (VarP $ mkName "npColInit")
(NormalB (RecConE evalParams $ map genRecFieldIniP params)) []
setParm = ValD (VarP $ mkName "npSetParm") (NormalB (VarE 'id)) []
d = DataD [] evalParams [] [RecC evalParams (map (genRecFieldDecP . fst) params)] [''Show]
i = InstanceD [] (AppT collectParams theInst) [ typeDec, colInit, colParm, setParm ]
d = DataD [] evalParams [] Nothing [RecC evalParams (map (genRecFieldDecP . fst) params)] [derivingShow]
i = InstanceD Nothing [] (AppT collectParams theInst) [ typeDec, colInit, colParm, setParm ]
return [d, i]

-- Generate the parts for EvalWeights
evalWeights :: Name
evalWeights = mkName "EvalWeights"

genRecFieldDecW :: String -> VarStrictType
genRecFieldDecW fld = (fldName, IsStrict, ConT midEndType)
genRecFieldDecW fld = (fldName, Bang NoSourceUnpackedness SourceStrict, ConT midEndType)
where fldName = mkName fld
midEndType = mkName "MidEnd"

Expand All @@ -210,8 +214,9 @@ genEvalWeights = do
rfds = map (genRecFieldDecW . fst) weights
colInit = ValD (VarP $ mkName "npColInit") (NormalB (RecConE evalWeights inis)) []
theInst = ConT evalWeights
typeDec = TySynInstD (mkName "CollectFor") (TySynEqn [theInst] theInst)
collectFor = AppT (ConT (mkName "CollectFor")) theInst
typeDec = TySynInstD (TySynEqn Nothing collectFor theInst)
setParm = ValD (VarP $ mkName "npSetParm") (NormalB (VarE 'id)) []
d = DataD [] evalWeights [] [RecC evalWeights rfds] [''Show]
i = InstanceD [] (AppT collectParams theInst) [ typeDec, colInit, colParm, setParm ]
d = DataD [] evalWeights [] Nothing [RecC evalWeights rfds] [derivingShow]
i = InstanceD Nothing [] (AppT collectParams theInst) [ typeDec, colInit, colParm, setParm ]
return [d, i]
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ flags: {}
packages:
- '.'
extra-deps: []
resolver: lts-6.35
resolver: lts-16.20

0 comments on commit 090e54f

Please sign in to comment.