您正在查看 "Haskell" 分类下的文章 2009-05-12 16:50 2009-04-30 9:37 本篇介绍 Data.Maybe 所有导出函数
maybe :: b -> (a -> b) -> Maybe a -> b
isJust :: Maybe a -> Bool
isNothing :: Maybe a -> Bool
fromJust :: Maybe a -> a
fromMaybe |
2009-04-29 17:25 本篇介绍除了 Prelude 模块所涉及函数外的其它 List 函数
elemIndex :: (Eq a) => a -> [a] -> Maybe Int
elemIndices :: (Eq a) => a -> [a] -> [Int]
findInde :: (a -> Bool) -> [a] -> Maybe In |
2009-04-29 9:54 本篇收录 Haskell 的经典代码,持续更新中
无限长的列表
makeList :: [Int]
makeList = 1 : makeList
Fibonacci 数列
|
2009-04-28 22:27 Haskell 可以这样绑定,一举三得
Prelude> let xss@(x:xs) = [1, 2, 3, 4]
Prelude> xss
[1,2,3,4]
Prelude> x
1
Prelude> xs
[2,3,4]
以前一直认为这种写法只是用在 pattern match 中呢 ?没想到直接绑定也可以
python 中有一种写法:
>>> point = x, y = 1, 2
>>> point
|
2009-04-28 15:19 code:
m # n = m + n
run:
*Main> 1 ^ 2 # 3
1
*Main> :i (#)
(#) :: (Num a) => a -> a -> a -- Defined at t.hs:3:2
*Main> :i (^)
(^) :: (Num a, Integral b) => a -> b -> a -- Defined in GHC.Real
infixr 8 ^
*Main> 1 # (+2).(*3) 4
<interactive>:1:0:
precedence parsing error
cannot mix `(#)' |
2009-04-28 10:59 module Complex (
Complex((:+)), realPart, imagPart, conjugate,
mkPolar, cis, polar, magnitude, phase ) where
infix 6 :+
data (RealFloat a) => Complex a = !a :+ !a
realPart, imagPart :: (RealFloat a) => Complex a -> a
conjugate :: (RealFloat a) => Complex a -> Complex a
mkPolar :: (RealFloat a) => a -> a -> Complex a
cis :: (RealFloat a) => a -> Complex a
polar :: (RealFloat a) => Complex a -> ( |
2009-04-27 19:12 module Ratio (
Ratio, Rational, (%), numerator, denominator, approxRational ) where
infixl 7 %
data (Integral a) => Ratio a = ...
type Rational = Ratio Integer
(%) :: (Integral a) => a -> a -> Ratio a
numerator, denominator :: (Integral a) => Ratio a -> a
approxRational :: (RealFrac a) => a -> a -> Rational
instance (Integral a) => Eq (Ratio a) where ...
instance (Integral a) => Ord (Ratio a) wher |
2009-04-26 17:12 2009-04-25 18:24 接上篇:FP的Combinator 特性--转帖1
我说C++和Fortran等语言背离了图灵的基本计算理论,并不是说它们有什么不好的地方, 它们正是最贯彻执行了冯·诺依曼这一经典体系结构的东西。但是在讨论到函数式编程的时候,如果不这样区分清楚,就根本不能触及到函数式编程的本质。
"金字塔矗立在那里千年不变,而有机体则必须演化,否则就会消亡" 大家有可能觉得这些话似乎有些夸张而且不可理解。那么我们现在来体会一下什么是金字塔和有机体的区别。在这里我同时会介绍Monad Combinator。 |
2009-04-25 18:24 2009-04-24 23:06 2009-04-24 22:42 2009-04-23 22:27 (.&.) :: a -> a -> a
(.|.) :: a -> a -> a
xor :: a -> a -> a
complement :: a -> a
shiftL :: a -> Int -> a
shiftR :: a -> Int -> a
rotateL :: a -> Int -> a |
2009-04-23 21:43 isAscii :: Char -> Bool
isLatin1 :: Char -> Bool
isControl :: Char -> Bool
isSpace :: Char -> Bool
isLower :: Char -> Bool
isUpper :: Char -> Bool
isAlpha :: Char -> Bool
isAlphaNum |
| | |