シリーズ: haskell
haskell
18 行
· 更新日 2026-02-03
exercise_3_1.hs
haskell/Week_6_Lab/exercise_3_1.hs
-- Define the myFilter function
myFilter :: (a -> Bool) -> [a] -> [a]
myFilter _ [] = [] -- Base case: if the list is empty, return an empty list
myFilter f (x:xs)
| f x = x : myFilter f xs -- If the function evaluates to True, include the element
| otherwise = myFilter f xs -- Otherwise, skip the element
-- Function to filter valid marks (between 0 and 100)
filterMark :: [Integer] -> [Integer]
filterMark = myFilter (\x -> x >= 0 && x <= 100)
-- Function to filter palindromes
filterPalindromes :: [String] -> [String]
filterPalindromes = myFilter (\s -> s == reverse s)
-- Function to filter strings by length
filterByLength :: Int -> [String] -> [String]
filterByLength n = myFilter (\s -> length s >= n)
関連記事
haskell
haskell
更新日 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
記事を読む →
haskell
haskell
更新日 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
記事を読む →
haskell
haskell
更新日 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
記事を読む →
haskell
haskell
更新日 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
記事を読む →
haskell
haskell
更新日 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
記事を読む →
haskell
haskell
更新日 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
記事を読む →