Cleanup some compiler warnings
This commit is contained in:
+46
-94
@@ -1,97 +1,3 @@
|
||||
/home/justin/Haskell/loop/src/Dodge/Placement/PlaceSpot.hs:159:5-30: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding: Patterns of type ‘[Point2]’ not matched: []
|
||||
|
|
||||
159 | (p : ps) = orderPolygon qs
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Dodge/Update.hs:319:30-33: warning: [-Wunused-matches]
|
||||
Defined but not used: ‘ssel’
|
||||
|
|
||||
319 | Just (MouseInvChosen ssel esel) -> w
|
||||
| ^^^^
|
||||
/home/justin/Haskell/loop/src/Dodge/Update.hs:319:35-38: warning: [-Wunused-matches]
|
||||
Defined but not used: ‘esel’
|
||||
|
|
||||
319 | Just (MouseInvChosen ssel esel) -> w
|
||||
| ^^^^
|
||||
/home/justin/Haskell/loop/src/Dodge/Update.hs:341:38: warning: [-Wunused-matches]
|
||||
Defined but not used: ‘k’
|
||||
|
|
||||
341 | shiftInvItemsUp (_,i) (_,j) (Just (_,k)) w = w
|
||||
| ^
|
||||
/home/justin/Haskell/loop/src/Dodge/Update.hs:351:40: warning: [-Wunused-matches]
|
||||
Defined but not used: ‘k’
|
||||
|
|
||||
351 | shiftInvItemsDown (_,i) (_,j) (Just (_,k)) w = w
|
||||
| ^
|
||||
/home/justin/Haskell/loop/src/Dodge/Room/RezBox.hs:54:22: warning: [GHC-47082] [-Woperator-whitespace-ext-conflict]
|
||||
The prefix use of a ‘$’ would denote an untyped splice
|
||||
were the TemplateHaskell extension enabled.
|
||||
Suggested fix: Add whitespace after the ‘$’.
|
||||
|
|
||||
54 | shuffleLinks $(roomRectAutoLinks w h){_rmPmnts = []}
|
||||
| ^
|
||||
/home/justin/Haskell/loop/src/Dodge/Room/RezBox.hs:120:44: warning: [GHC-47082] [-Woperator-whitespace-ext-conflict]
|
||||
The prefix use of a ‘$’ would denote an untyped splice
|
||||
were the TemplateHaskell extension enabled.
|
||||
Suggested fix: Add whitespace after the ‘$’.
|
||||
|
|
||||
120 | let n = length $ filter bottomEdgeTest $_rmLinks centralRoom
|
||||
| ^
|
||||
/home/justin/Haskell/loop/src/Dodge/Room/RezBox.hs:122:29: warning: [GHC-47082] [-Woperator-whitespace-ext-conflict]
|
||||
The prefix use of a ‘$’ would denote an untyped splice
|
||||
were the TemplateHaskell extension enabled.
|
||||
Suggested fix: Add whitespace after the ‘$’.
|
||||
|
|
||||
122 | tToBTree "rezBoxes" $treeFromTrunk [rezBox thecol, door] $
|
||||
| ^
|
||||
/home/justin/Haskell/loop/src/Dodge/HeldUse.hs:177:5-59: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘([Float], StdGen)’ not matched:
|
||||
([], _)
|
||||
([_], _)
|
||||
([_, _], _)
|
||||
([_, _, _], _)
|
||||
|
|
||||
177 | (a : b : c : d : _, g) = runState thestate $ _randGen w -- randomRs (2, 20) (_randGen w)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/RandomHelp.hs:36:9-35: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘([a], [a])’ not matched: (_, [])
|
||||
|
|
||||
36 | let (zs, w : ws) = splitAt i ys
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/RandomHelp.hs:51:17-46: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘([b], [b])’ not matched: (_, [])
|
||||
|
|
||||
51 | let (as, b : bs) = splitAt rand ys
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Multiset.hs:50:9: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding: Patterns of type ‘[a]’ not matched: []
|
||||
|
|
||||
50 | (q:qs) = take (n-k+1) ys
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Dodge/Render/Connectors.hs:41:5: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘(Maybe Float, Maybe Float)’ not matched:
|
||||
(Nothing, _)
|
||||
((Just _), Nothing)
|
||||
|
|
||||
41 | (Just ymin,Just ymax) = minAndMax $ y : map (^._y) sps
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Dodge/Particle/Draw.hs:15:5: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘[Geometry.Data.Point2]’ not matched: []
|
||||
|
|
||||
15 | (sp : ps) = _lzPoints pt
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Polyhedra.hs:68:5: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
@@ -142,6 +48,31 @@
|
||||
|
|
||||
302 | (x : xs) = w ^. wCam . camBoundBox
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/RandomHelp.hs:36:9: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘([a], [a])’ not matched: (_, [])
|
||||
|
|
||||
36 | let (zs, w : ws) = splitAt i ys
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/RandomHelp.hs:51:17: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘([b], [b])’ not matched: (_, [])
|
||||
|
|
||||
51 | let (as, b : bs) = splitAt rand ys
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Dodge/HeldUse.hs:177:5: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
Patterns of type ‘([Float], StdGen)’ not matched:
|
||||
([], _)
|
||||
([_], _)
|
||||
([_, _], _)
|
||||
([_, _, _], _)
|
||||
|
|
||||
177 | (a : b : c : d : _, g) = runState thestate $ _randGen w -- randomRs (2, 20) (_randGen w)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Tile.hs:36:5: warning: [GHC-62161] [-Wincomplete-uni-patterns]
|
||||
Pattern match(es) are non-exhaustive
|
||||
In a pattern binding:
|
||||
@@ -151,3 +82,24 @@
|
||||
|
|
||||
36 | (c:d:_) = poly
|
||||
| ^^^^^^^^^^^^^^
|
||||
/home/justin/Haskell/loop/src/Dodge/Room/RezBox.hs:54:22: warning: [GHC-47082] [-Woperator-whitespace-ext-conflict]
|
||||
The prefix use of a ‘$’ would denote an untyped splice
|
||||
were the TemplateHaskell extension enabled.
|
||||
Suggested fix: Add whitespace after the ‘$’.
|
||||
|
|
||||
54 | shuffleLinks $(roomRectAutoLinks w h){_rmPmnts = []}
|
||||
| ^
|
||||
/home/justin/Haskell/loop/src/Dodge/Room/RezBox.hs:120:44: warning: [GHC-47082] [-Woperator-whitespace-ext-conflict]
|
||||
The prefix use of a ‘$’ would denote an untyped splice
|
||||
were the TemplateHaskell extension enabled.
|
||||
Suggested fix: Add whitespace after the ‘$’.
|
||||
|
|
||||
120 | let n = length $ filter bottomEdgeTest $_rmLinks centralRoom
|
||||
| ^
|
||||
/home/justin/Haskell/loop/src/Dodge/Room/RezBox.hs:122:29: warning: [GHC-47082] [-Woperator-whitespace-ext-conflict]
|
||||
The prefix use of a ‘$’ would denote an untyped splice
|
||||
were the TemplateHaskell extension enabled.
|
||||
Suggested fix: Add whitespace after the ‘$’.
|
||||
|
|
||||
122 | tToBTree "rezBoxes" $treeFromTrunk [rezBox thecol, door] $
|
||||
| ^
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
module Dodge.Particle.Draw where
|
||||
|
||||
import Dodge.Data.Laser
|
||||
import Picture
|
||||
|
||||
drawTargetLaser :: Laser -> Picture
|
||||
drawTargetLaser pt =
|
||||
setLayer BloomNoZWrite $
|
||||
fold
|
||||
[ setDepth 19 . color (brightX 0 0.5 col) $ thickLine 5 (sp : ps)
|
||||
, setDepth 19.5 . color (brightX 5 1 col) $ thickLine 1 (sp : ps)
|
||||
]
|
||||
where
|
||||
col = _lzColor pt
|
||||
(sp : ps) = _lzPoints pt
|
||||
@@ -1,3 +1,4 @@
|
||||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
|
||||
{- | deals with placement of objects within the world
|
||||
after they have had their coordinates set by the layout
|
||||
-}
|
||||
@@ -5,7 +6,6 @@ module Dodge.Placement.PlaceSpot (
|
||||
placeSpot,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Color
|
||||
import Control.Lens
|
||||
import Control.Monad.State
|
||||
@@ -22,6 +22,7 @@ import Dodge.Placement.Shift
|
||||
import Dodge.ShiftPoint
|
||||
import Geometry
|
||||
import qualified IntMapHelp as IM
|
||||
import NewInt
|
||||
import Picture
|
||||
import System.Random
|
||||
|
||||
@@ -30,7 +31,8 @@ import System.Random
|
||||
placeSpot :: (GenWorld, Room) -> Placement -> ((GenWorld, Room), [Placement])
|
||||
placeSpot (w, rm) plmnt = case plmnt of
|
||||
Placement{_plSpot = PSRoomRand i f} -> placeSpotRoomRand rm i f plmnt w
|
||||
Placement{_plSpot = PSPos extract eff fallback} -> placeSpotUsingLink w rm plmnt extract eff fallback
|
||||
Placement{_plSpot = PSPos extract eff fallback} ->
|
||||
placeSpotUsingLink w rm plmnt extract eff fallback
|
||||
Placement{} -> placePlainPSSpot w rm plmnt shift
|
||||
PlacementUsingPos p subpl -> placeSpot (w, rm) (subpl (shiftPoint3By shift p))
|
||||
RandomPlacement rplmnt -> placeRandomPlacement rplmnt w rm
|
||||
@@ -39,14 +41,23 @@ placeSpot (w, rm) plmnt = case plmnt of
|
||||
shift = _rmShift rm
|
||||
|
||||
placePickOne :: Int -> Placement -> Room -> GenWorld -> GenWorld
|
||||
placePickOne i pl rm w = w & genPlacements %~ IM.insertWith (++) i [(pl, fromJust (_rmMID rm))]
|
||||
placePickOne i pl rm = genPlacements %~ IM.insertWith (++) i [(pl, fromJust (_rmMID rm))]
|
||||
|
||||
placeRandomPlacement :: State StdGen Placement -> GenWorld -> Room -> ((GenWorld, Room), [Placement])
|
||||
placeRandomPlacement ::
|
||||
State StdGen Placement ->
|
||||
GenWorld ->
|
||||
Room ->
|
||||
((GenWorld, Room), [Placement])
|
||||
placeRandomPlacement rplmnt w rm = placeSpot (w & gwWorld . randGen .~ g, rm) plmnt'
|
||||
where
|
||||
(plmnt', g) = runState rplmnt (_randGen (_gwWorld w))
|
||||
|
||||
placePlainPSSpot :: GenWorld -> Room -> Placement -> DPoint2 -> ((GenWorld, Room), [Placement])
|
||||
placePlainPSSpot ::
|
||||
GenWorld ->
|
||||
Room ->
|
||||
Placement ->
|
||||
DPoint2 ->
|
||||
((GenWorld, Room), [Placement])
|
||||
placePlainPSSpot w rm plmnt shift =
|
||||
let (i, w') = placeSpotID (shiftPSBy shift (_plSpot plmnt)) (_plType plmnt) w
|
||||
newplmnt = plmnt & plMID ?~ i
|
||||
@@ -100,8 +111,12 @@ placeSpotID' ps pt w = case pt of
|
||||
PutProp prp -> plNewUpID (cWorld . lWorld . props) prID (mvProp p rot prp) w
|
||||
PutButton bt -> plNewUpID (cWorld . lWorld . buttons) btID (mvButton p rot bt) w
|
||||
PutTerminal tm -> plNewUpID (cWorld . lWorld . terminals) tmID tm w
|
||||
PutFlIt itm -> plNewUpID (cWorld . lWorld . floorItems . unNIntMap) (flItID . unNInt)
|
||||
(createFlIt p rot itm) w
|
||||
PutFlIt itm ->
|
||||
plNewUpID
|
||||
(cWorld . lWorld . floorItems . unNIntMap)
|
||||
(flItID . unNInt)
|
||||
(createFlIt p rot itm)
|
||||
w
|
||||
PutCrit cr -> plNewUpID (cWorld . lWorld . creatures) crID (mvCr p rot cr) w
|
||||
PutForeground fs -> plNewUpID (cWorld . lWorld . foregroundShapes) fsID (mvFS p rot fs) w
|
||||
PutDecoration pic -> plNewID (cWorld . lWorld . decorations) (shiftDec p rot pic) w
|
||||
@@ -134,7 +149,7 @@ placeSpotID' ps pt w = case pt of
|
||||
doShift = shiftPointBy (p, rot)
|
||||
|
||||
shiftDec :: Point2 -> Float -> Picture -> Picture
|
||||
shiftDec p r pic = uncurryV translate p $ rotate r pic
|
||||
shiftDec p r = uncurryV translate p . rotate r
|
||||
|
||||
evaluateRandPS :: State StdGen PSType -> PlacementSpot -> World -> (Int, World)
|
||||
evaluateRandPS rgen ps w = placeSpotID' ps evaluatedType (set randGen g w)
|
||||
@@ -147,12 +162,8 @@ evaluateRandPS rgen ps w = placeSpotID' ps evaluatedType (set randGen g w)
|
||||
---- where
|
||||
---- rmCrossPaths w = foldr (uncurry obstructPathsCrossing) w $ loopPairs ps
|
||||
|
||||
--placeWalls :: [Point2] -> Wall -> IM.IntMap Wall -> IM.IntMap Wall
|
||||
--placeWalls qs wl wls = foldl' (addPane wl) wls pairs
|
||||
-- where
|
||||
-- (p:ps) = orderPolygon qs
|
||||
-- pairs = zip (ps ++ [p]) (p:ps)
|
||||
|
||||
-- this function is the reason for the warning suppression
|
||||
-- remove the warning suppression if it changes
|
||||
placeWallPoly :: [Point2] -> Wall -> World -> World
|
||||
placeWallPoly qs wl w = foldl' (addPane wl) w pairs
|
||||
where
|
||||
@@ -160,14 +171,10 @@ placeWallPoly qs wl w = foldl' (addPane wl) w pairs
|
||||
pairs = zip (ps ++ [p]) (p : ps)
|
||||
|
||||
addPane :: Wall -> World -> (Point2, Point2) -> World
|
||||
--addPane wl w l = w & walls %~ IM.insert wlid (wl { _wlLine = l, _wlID = wlid })
|
||||
addPane wl w l =
|
||||
w & plNew (cWorld . lWorld . walls) wlID (wl & wlLine .~ l)
|
||||
& fst . uncurry (obstructPathsCrossing WallObstacle) l
|
||||
|
||||
-- where
|
||||
-- wlid = IM.newKey (_walls w)
|
||||
|
||||
mvProp :: Point2 -> Float -> Prop -> Prop
|
||||
mvProp p a = (prRot +~ a) . (prPos %~ ((p +.+) . rotateV a))
|
||||
|
||||
|
||||
@@ -1,42 +1,56 @@
|
||||
module Dodge.Render.Connectors
|
||||
( zConnect
|
||||
, zConnectCol
|
||||
, lConnect
|
||||
, lConnectMulti
|
||||
) where
|
||||
import FoldableHelp
|
||||
import Picture
|
||||
import Geometry
|
||||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
|
||||
|
||||
module Dodge.Render.Connectors (
|
||||
zConnect,
|
||||
zConnectCol,
|
||||
lConnect,
|
||||
lConnectMulti,
|
||||
) where
|
||||
|
||||
import Control.Lens
|
||||
import FoldableHelp
|
||||
import Geometry
|
||||
import Linear.V2
|
||||
import Picture
|
||||
|
||||
zConnect :: Point2 -> Point2 -> Picture
|
||||
zConnect (V2 x y) (V2 a b) = line $ map toV2
|
||||
[(x,y)
|
||||
,(0.5 * (x+a), y)
|
||||
,(0.5 * (x+a), b)
|
||||
,(a, b)
|
||||
]
|
||||
zConnect (V2 x y) (V2 a b) =
|
||||
line $
|
||||
map
|
||||
toV2
|
||||
[ (x, y)
|
||||
, (0.5 * (x + a), y)
|
||||
, (0.5 * (x + a), b)
|
||||
, (a, b)
|
||||
]
|
||||
|
||||
zConnectCol :: Point2 -> Point2 -> Color -> Color -> Color -> Color -> Picture
|
||||
zConnectCol (V2 x y) (V2 a b) c1 c2 c3 c4 = lineCol $ zip
|
||||
( map toV2
|
||||
[(x,y)
|
||||
,(0.5 * (x+a), y)
|
||||
,(0.5 * (x+a), b)
|
||||
,(a, b)
|
||||
]
|
||||
) [c1,c2,c3,c4]
|
||||
zConnectCol (V2 x y) (V2 a b) c1 c2 c3 c4 =
|
||||
lineCol $
|
||||
zip
|
||||
( map
|
||||
toV2
|
||||
[ (x, y)
|
||||
, (0.5 * (x + a), y)
|
||||
, (0.5 * (x + a), b)
|
||||
, (a, b)
|
||||
]
|
||||
)
|
||||
[c1, c2, c3, c4]
|
||||
|
||||
lConnect :: Point2 -> Point2 -> Picture
|
||||
lConnect sp@(V2 _ y) ep@(V2 x _) = line
|
||||
[ sp
|
||||
, V2 x y
|
||||
, ep
|
||||
]
|
||||
lConnect sp@(V2 _ y) ep@(V2 x _) =
|
||||
line
|
||||
[ sp
|
||||
, V2 x y
|
||||
, ep
|
||||
]
|
||||
|
||||
-- this function is the reason for the incomplete-uni-patterns warning suppression
|
||||
lConnectMulti :: [Point2] -> Point2 -> Picture
|
||||
lConnectMulti sps (V2 x y) = line [V2 x ymin,V2 x ymax] <>
|
||||
foldMap f sps
|
||||
lConnectMulti sps (V2 x y) =
|
||||
line [V2 x ymin, V2 x ymax]
|
||||
<> foldMap f sps
|
||||
where
|
||||
(Just ymin,Just ymax) = minAndMax $ y : map (^._y) sps
|
||||
f (V2 x' y') = line [V2 x' y',V2 x y']
|
||||
(Just ymin, Just ymax) = minAndMax $ y : map (^. _y) sps
|
||||
f (V2 x' y') = line [V2 x' y', V2 x y']
|
||||
|
||||
+3
-3
@@ -316,7 +316,7 @@ updateMouseInventorySelection' sss cfig w
|
||||
Just (MouseInvChosen ssel esel)
|
||||
| maybe False (>esel) $ inverseSelBoundaryDown cfig ldp sss mpos -> w
|
||||
& shiftInvItemsDown ssel esel (inverseSelBoundaryDown cfig ldp sss mpos)
|
||||
Just (MouseInvChosen ssel esel) -> w
|
||||
Just (MouseInvChosen{}) -> w
|
||||
_ -> w
|
||||
& hud . hudElement . subInventory . nsSelected .~ NoMouseSel
|
||||
| otherwise = case w ^? hud . hudElement . subInventory . nsSelected of
|
||||
@@ -338,7 +338,7 @@ updateMouseInventorySelection' sss cfig w
|
||||
mysel = inverseSelSecYint (posSelSecYint cfig ldp (mpos ^. _y)) sss
|
||||
|
||||
shiftInvItemsUp :: (Int,Int) -> (Int,Int) -> Maybe (Int,Int) -> World -> World
|
||||
shiftInvItemsUp (_,i) (_,j) (Just (_,k)) w = w
|
||||
shiftInvItemsUp (_,i) (_,j) Just{} w = w
|
||||
& flip (foldl' f) [i..j]
|
||||
& hud . hudElement . subInventory . nsSelected . misChosenStart . _2 -~ 1
|
||||
& hud . hudElement . subInventory . nsSelected . misChosenEnd . _2 -~ 1
|
||||
@@ -348,7 +348,7 @@ shiftInvItemsUp (_,i) (_,j) (Just (_,k)) w = w
|
||||
shiftInvItemsUp _ _ Nothing w = w
|
||||
|
||||
shiftInvItemsDown :: (Int,Int) -> (Int,Int) -> Maybe (Int,Int) -> World -> World
|
||||
shiftInvItemsDown (_,i) (_,j) (Just (_,k)) w = w
|
||||
shiftInvItemsDown (_,i) (_,j) Just{} w = w
|
||||
& flip (foldl' f) (reverse [i..j])
|
||||
& hud . hudElement . subInventory . nsSelected . misChosenStart . _2 +~ 1
|
||||
& hud . hudElement . subInventory . nsSelected . misChosenEnd . _2 +~ 1
|
||||
|
||||
+35
-28
@@ -1,16 +1,19 @@
|
||||
{-# LANGUAGE TupleSections #-}
|
||||
{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}
|
||||
|
||||
module Multiset where
|
||||
|
||||
import Control.Monad
|
||||
import qualified Data.IntSet as IS
|
||||
import qualified Data.Map.Strict as M
|
||||
import qualified IntMapHelp as IM
|
||||
import qualified Data.IntSet as IS
|
||||
import Control.Monad
|
||||
|
||||
-- naive solution
|
||||
powlistUpToN' :: Int -> [a] ->[[a]]
|
||||
powlistUpToN' :: Int -> [a] -> [[a]]
|
||||
powlistUpToN' _ [] = [[]]
|
||||
powlistUpToN' n (x:xs)
|
||||
| n <=0 = [[]]
|
||||
| otherwise = ((x:) <$> powlistUpToN' (n-1) xs) ++ powlistUpToN' n xs
|
||||
powlistUpToN' n (x : xs)
|
||||
| n <= 0 = [[]]
|
||||
| otherwise = ((x :) <$> powlistUpToN' (n -1) xs) ++ powlistUpToN' n xs
|
||||
|
||||
-- adapted from
|
||||
-- https://stackoverflow.com/questions/21265454/subsequences-of-length-n-from-list-performance/59932616#59932616
|
||||
@@ -18,47 +21,51 @@ powlistUpToN' n (x:xs)
|
||||
-- there is a (probably) faster SO answer that produces power lists of size
|
||||
-- exactly N, but that answer is harder to adapt
|
||||
powlistUpToN :: Int -> [a] -> [[a]]
|
||||
powlistUpToN n xs = concat $ drop (length xs-n) (subseqsBySize xs)
|
||||
powlistUpToN n xs = concat $ drop (length xs - n) (subseqsBySize xs)
|
||||
where
|
||||
subseqsBySize [] = [[[]]]
|
||||
subseqsBySize (y:ys) =
|
||||
subseqsBySize (y : ys) =
|
||||
let next = subseqsBySize ys
|
||||
in zipWith (++) ([]:next) (map (map (y:)) next ++ [[]])
|
||||
in zipWith (++) ([] : next) (map (map (y :)) next ++ [[]])
|
||||
|
||||
powlistUpToN'' :: Int -> [a] -> [[a]]
|
||||
powlistUpToN'' n xs =
|
||||
powlistUpToN'' n xs =
|
||||
let l = length xs
|
||||
-- in if n > l then [] else concat $ drop (l-n) (subseqsBySize xs)
|
||||
in if n > l
|
||||
then concat $ subseqsBySize xs
|
||||
else concat $ drop (l-n) (subseqsBySize xs)
|
||||
in -- in if n > l then [] else concat $ drop (l-n) (subseqsBySize xs)
|
||||
if n > l
|
||||
then concat $ subseqsBySize xs
|
||||
else concat $ drop (l - n) (subseqsBySize xs)
|
||||
where
|
||||
subseqsBySize [] = [[[]]]
|
||||
subseqsBySize (y:ys) =
|
||||
subseqsBySize (y : ys) =
|
||||
let next = subseqsBySize ys
|
||||
in zipWith (++) ([]:next) (map (map (y:)) next ++ [[]])
|
||||
in zipWith (++) ([] : next) (map (map (y :)) next ++ [[]])
|
||||
|
||||
-- this is the code producing all exactly n length sublists
|
||||
-- it is the reason for the incomplete-uni-patterns warning suppression
|
||||
combinationsOf :: Int -> [a] -> [[a]]
|
||||
combinationsOf 1 as = map pure as
|
||||
combinationsOf k' as@(_:xs) = run (l-1) (k'-1) as $ combinationsOf (k'-1) xs
|
||||
combinationsOf 1 as = map pure as
|
||||
combinationsOf k' as@(_ : xs) = run (l -1) (k' -1) as $ combinationsOf (k' -1) xs
|
||||
where
|
||||
l = length as
|
||||
run :: Int -> Int -> [a] -> [[a]] -> [[a]]
|
||||
run n k ys cs
|
||||
| n == k = map (ys ++) cs
|
||||
| otherwise = map (q:) cs ++ run (n-1) k qs (drop dc cs)
|
||||
run n k ys cs
|
||||
| n == k = map (ys ++) cs
|
||||
| otherwise = map (q :) cs ++ run (n -1) k qs (drop dc cs)
|
||||
where
|
||||
(q:qs) = take (n-k+1) ys
|
||||
dc = product [(n-k+1)..(n-1)] `div` product [1..(k-1)]
|
||||
(q : qs) = take (n - k + 1) ys
|
||||
dc = product [(n - k + 1) .. (n -1)] `div` product [1 .. (k -1)]
|
||||
combinationsOf _ [] = []
|
||||
|
||||
-- exponential, so don't use it on long lists
|
||||
powlist :: [a] -> [[a]]
|
||||
powlist = filterM (const [True,False])
|
||||
powlist = filterM (const [True, False])
|
||||
|
||||
toMultiset :: Ord a => [a] -> M.Map a Int
|
||||
toMultiset = foldr (uncurry (M.insertWith (+)) . (, 1)) M.empty
|
||||
toMultiset = foldr (uncurry (M.insertWith (+)) . (,1)) M.empty
|
||||
|
||||
invertIntMap :: Ord a => IM.IntMap a -> M.Map a IS.IntSet
|
||||
invertIntMap = IM.foldrWithKey
|
||||
(\k x -> M.insertWith IS.union x (IS.singleton k))
|
||||
M.empty
|
||||
invertIntMap =
|
||||
IM.foldrWithKey
|
||||
(\k x -> M.insertWith IS.union x (IS.singleton k))
|
||||
M.empty
|
||||
|
||||
Reference in New Issue
Block a user