Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Collections/Haskell/collections-1.hs
Normal file
1
Task/Collections/Haskell/collections-1.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1, 2, 3, 4, 5]
|
||||
1
Task/Collections/Haskell/collections-2.hs
Normal file
1
Task/Collections/Haskell/collections-2.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
1 : [2, 3, 4]
|
||||
1
Task/Collections/Haskell/collections-3.hs
Normal file
1
Task/Collections/Haskell/collections-3.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
[1, 2] ++ [3, 4]
|
||||
1
Task/Collections/Haskell/collections-4.hs
Normal file
1
Task/Collections/Haskell/collections-4.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
concat [[1, 2], [3, 4], [5, 6, 7]]
|
||||
19
Task/Collections/Haskell/collections-5.hs
Normal file
19
Task/Collections/Haskell/collections-5.hs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Data.Array (Array, listArray, Ix, (!))
|
||||
|
||||
triples :: Array Int (Char, String, String)
|
||||
triples =
|
||||
listArray (0, 11) $
|
||||
zip3
|
||||
"鼠牛虎兔龍蛇馬羊猴鸡狗豬" -- 生肖 shengxiao – symbolic animals
|
||||
(words "shǔ niú hǔ tù lóng shé mǎ yáng hóu jī gǒu zhū")
|
||||
(words "rat ox tiger rabbit dragon snake horse goat monkey rooster dog pig")
|
||||
|
||||
indexedItem
|
||||
:: Ix i
|
||||
=> Array i (Char, String, String) -> i -> String
|
||||
indexedItem a n =
|
||||
let (c, w, w1) = a ! n
|
||||
in c : unwords ["\t", w, w1]
|
||||
|
||||
main :: IO ()
|
||||
main = (putStrLn . unlines) $ indexedItem triples <$> [2, 4, 6]
|
||||
20
Task/Collections/Haskell/collections-6.hs
Normal file
20
Task/Collections/Haskell/collections-6.hs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import qualified Data.Map as M
|
||||
import Data.Maybe (isJust)
|
||||
|
||||
mapSample :: M.Map String Int
|
||||
mapSample =
|
||||
M.fromList
|
||||
[ ("alpha", 1)
|
||||
, ("beta", 2)
|
||||
, ("gamma", 3)
|
||||
, ("delta", 4)
|
||||
, ("epsilon", 5)
|
||||
, ("zeta", 6)
|
||||
]
|
||||
|
||||
maybeValue :: String -> Maybe Int
|
||||
maybeValue = flip M.lookup mapSample
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
print $ sequence $ filter isJust (maybeValue <$> ["beta", "delta", "zeta"])
|
||||
10
Task/Collections/Haskell/collections-7.hs
Normal file
10
Task/Collections/Haskell/collections-7.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import qualified Data.Set as S
|
||||
|
||||
setA :: S.Set String
|
||||
setA = S.fromList ["alpha", "beta", "gamma", "delta", "epsilon"]
|
||||
|
||||
setB :: S.Set String
|
||||
setB = S.fromList ["delta", "epsilon", "zeta", "eta", "theta"]
|
||||
|
||||
main :: IO ()
|
||||
main = (print . S.toList) (S.intersection setA setB)
|
||||
Loading…
Add table
Add a link
Reference in a new issue