随笔分类 -  Haskell

摘要:List comprehension 序列内涵??恕我英语垃圾翻译不出来 但是它是一种应用在序列上的函数,写起来就像集合一样 相当于是用旧序列生成新序列,不妨翻译为序列生成 比如 [x^2 | x <- [1..10]] --[1,4,9,16,25,36,49,64,81,100] [(x,y) 阅读全文
posted @ 2021-11-16 22:05 liankewei123456 阅读(54) 评论(0) 推荐(0) 编辑
摘要:Haskell学习笔记--函数定义 if 语句 signum :: Int -> Int signum n = if n < 0 then -1 else if n==0 then 0 else 1 Guarded equtions signum n | n > 0 = 1 | n < 0 = -1 阅读全文
posted @ 2021-11-16 21:07 liankewei123456 阅读(54) 评论(0) 推荐(0) 编辑
摘要:Haskell学习笔记--The state monad 状态变换器 快快快在回宿舍前搞完 失败了 状态变换器 type ST a = State -> ( a , State ) 返回变换后的状态和一个参数a type定义的类型不能被弄成monad,所以改成用newtype newtype ST 阅读全文
posted @ 2021-11-14 22:19 liankewei123456 阅读(47) 评论(0) 推荐(0) 编辑
摘要:Monads 翻译叫 “单子” 或者 “一个自函子上的幺半群” 好吧除了让人费解没有什么用 同样举一个书上的例子 data Expr = Val Int | Div Expr Expr eval :: Expr -> Maybe Int eval (Val n) = Pure n eval (Div 阅读全文
posted @ 2021-11-13 20:37 liankewei123456 阅读(51) 评论(0) 推荐(0) 编辑
摘要:Haskell 学习笔记 -- functor / applicative 这部分肯定是 Haskell 中最最抽象的了,我上课就没懂( 还有什么范畴论,自闭了 Functor 函子 函子的意思是一类容器,它里面可以装各种东西 比如 [] \ Maybe \ Tree 要让一个数据结构成为 Func 阅读全文
posted @ 2021-11-13 20:03 liankewei123456 阅读(90) 评论(0) 推荐(0) 编辑
摘要:Haskell学习笔记--IO (是IO不是OI 下周考试,赶紧冲刺 data IO a A value of type IO a is a computation which, when performed, does some I/O before returning a value of ty 阅读全文
posted @ 2021-11-13 19:23 liankewei123456 阅读(38) 评论(0) 推荐(0) 编辑
摘要:type 类型别名 type IntList = [Int] 注意大写 newtype 类似data 但只允许有一个构造函数,构造函数只能有一个参数 newtype Cm = Cm double deriving Eq 优点:快 阅读全文
posted @ 2021-10-23 12:56 liankewei123456 阅读(60) 评论(0) 推荐(0) 编辑
摘要:数字类 这玩意就不鸡肋了,看起来还挺重要 quot 除法,向 0 取整 div 除法,向下取整 quot/rem 比 div/mod 快 ceiling /floor 向上/向下取整 阅读全文
posted @ 2021-10-23 12:53 liankewei123456 阅读(35) 评论(0) 推荐(0) 编辑
摘要:class 类 顾名思义就是一类玩意,他们有着相似的特点 Eq 等价类 Ord 有序类 Show/Read Num 数字类 + - * abs signum Integral 整数类 div mod Fractional 小数类 typeclass 类型类 这个翻译的...我快看不懂类字了 data 阅读全文
posted @ 2021-10-23 10:55 liankewei123456 阅读(67) 评论(0) 推荐(0) 编辑
摘要:Haskell学习笔记--scanl/scanr 类似foldl/flodr 但是将每一步都记录下来,保存为list scanl :: (b -> a -> b) -> b -> [a] -> [b] scanr :: (a -> b -> b) -> b -> [a] -> [b] eg. sca 阅读全文
posted @ 2021-10-22 21:34 liankewei123456 阅读(106) 评论(0) 推荐(0) 编辑
摘要:Haskell学习笔记--foldl/flodr foldl :: (b->a->b)->b->[a]->b f x y x0 [y_i] result foldl f v [] = v foldl f v (x:xs) = foldl f (f v x) xs 可以理解为从从头到尾使用 f fol 阅读全文
posted @ 2021-10-22 20:45 liankewei123456 阅读(145) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示