haskell笔记(2)
2016-10-19 20:28
211 查看
–module Picture where
–或module Picture {
Picture,
above,
sideByside,
filpV,
filpH,
pic1,pic2,
printPic
} where
foo :: Int -> Int
foo x = x ^mod ^2
–[foo x | x <- [2,3,2,4,3,3,12]] <==> map foo
–[f x | x <- xs]
–高阶函数,highorder
my_map :: (a -> b) -> [a] -> [b]
–my_map f xs = [f x | x <- xs]
my_map f [] = []
my_map f (x : xs) = (f x) : map f xs
boo :: Float -> Bool
boo x = x^2 > 10
–map boo [1..10]
–map boo [True, False]
–p :: a -> Bool 类型的函数可以表达某种性质
–另一种计算模式:[x | x <- xs, p x]
isEven :: Int -> Bool
isEven x = x ^mod ^2 == 0
my_filter :: (n -> Bool) -> [a] -> [a]
–my_filter p xs = [x | x <- xs, p x]
–my_filter isEven [1..10]
my_filter p [] = []
my_filter p (x : xs)
| p x = x : my_filter p xs
| otherwise = my_filter p xs
–图形及图形上的函数
type Picture = [String]
picl = {
” # ”
” # # ”
” # # ”
” ####### ” }
–用”\n”换行
helpF :: Picture -> String
helpF [] = []
helpF (x : xs) = x ++ “\n” ++ heloF xs
printPic :: Picture -> IO ()
printPic pic = putStr (unlines pic)
sideByside :: Picture -> Picture -> Picture
sideByside pic1 pic2 = [x ++ y |(x,y) <- zip pic1 pic2]
above :: Picture -> Picture -> Picture
above pic1 pic2 = pic1 ++ pic2
flipV :: Picture -> Picture
filpV pic = [ reverse line | line <- pic]
filpV pic = map reverse pic
flipH :: Picture -> Picture
flipH :: pic = reverse pic
mys :: Picture -> Picture
mys pic = above pic1 pic1
where
pic1 = sideByside pic pic
–或module Picture {
Picture,
above,
sideByside,
filpV,
filpH,
pic1,pic2,
printPic
} where
foo :: Int -> Int
foo x = x ^mod ^2
–[foo x | x <- [2,3,2,4,3,3,12]] <==> map foo
–[f x | x <- xs]
–高阶函数,highorder
my_map :: (a -> b) -> [a] -> [b]
–my_map f xs = [f x | x <- xs]
my_map f [] = []
my_map f (x : xs) = (f x) : map f xs
boo :: Float -> Bool
boo x = x^2 > 10
–map boo [1..10]
–map boo [True, False]
–p :: a -> Bool 类型的函数可以表达某种性质
–另一种计算模式:[x | x <- xs, p x]
isEven :: Int -> Bool
isEven x = x ^mod ^2 == 0
my_filter :: (n -> Bool) -> [a] -> [a]
–my_filter p xs = [x | x <- xs, p x]
–my_filter isEven [1..10]
my_filter p [] = []
my_filter p (x : xs)
| p x = x : my_filter p xs
| otherwise = my_filter p xs
–图形及图形上的函数
type Picture = [String]
picl = {
” # ”
” # # ”
” # # ”
” ####### ” }
–用”\n”换行
helpF :: Picture -> String
helpF [] = []
helpF (x : xs) = x ++ “\n” ++ heloF xs
printPic :: Picture -> IO ()
printPic pic = putStr (unlines pic)
sideByside :: Picture -> Picture -> Picture
sideByside pic1 pic2 = [x ++ y |(x,y) <- zip pic1 pic2]
above :: Picture -> Picture -> Picture
above pic1 pic2 = pic1 ++ pic2
flipV :: Picture -> Picture
filpV pic = [ reverse line | line <- pic]
filpV pic = map reverse pic
flipH :: Picture -> Picture
flipH :: pic = reverse pic
mys :: Picture -> Picture
mys pic = above pic1 pic1
where
pic1 = sideByside pic pic
相关文章推荐
- Haskell笔记(一)
- haskell笔记
- Haskell 笔记(三)类型系统
- 【笔记】Haskell
- Haskell语言学习笔记(2)
- haskell 乱搞笔记[原创]
- haskell学习笔记_函数
- Haskell 笔记 ②
- programming in haskell 读书笔记1
- haskell学习笔记:List Comprehensions
- Haskell 笔记(一)开始使用
- Haskell笔记 (五) 高阶函数
- Haskell 笔记(四)函数系统
- Haskell 笔记(二)List和元组
- Haskell学习笔记1
- haskell笔记二:foldl与foldr的效率(惰性计算与尾递归)
- Haskell学习笔记
- haskell 趣学指南笔记-1type and typeclass
- haskell 笔记
- Monad State in Haskell 笔记