Data.Text.Read Prelude> :set -XOverloadedStrings Prelude> :m +Data.Text.Read Prelude Data.Text.Read> decimal "123" Right (123,"") Prelude Data.Text.Read> decimal "abc" Left "input does not start with a digit&…
Data.Tree data Tree a = Node { rootLabel :: a, subForest :: Forest a } deriving (Eq, Read, Show) type Forest a = [Tree a] Data.Tree 是一种非空(存在根节点),可以有无限分支,每个节点均可有多路分支的Tree类型. Prelude Data.Tree> :t Node 1 Node 1 :: Num a => Forest a -> Tree a Prelud…
Map Prelude> import Data.Map as Map Prelude Map> :set -XOverloadedLists Prelude Map> OverloadedLists GHC 提供了语言扩展 OverloadedLists. 不使用这个语言扩展,所有的列表字面量都属于 [] 类型. 如果使用这个语言扩展,那么所有的列表字面量就都属于 IsList l => l 类型. Map, Set, Vector, Text, Array 都是 IsList…
Data.Tuple fst :: (a,b) -> a fst (x,_) = x snd :: (a,b) -> b snd (_,y) = y curry :: ((a, b) -> c) -> a -> b -> c curry f x y = f (x, y) uncurry :: (a -> b -> c) -> ((a, b) -> c) uncurry f p = f (fst p) (snd p) swap :: (a,b) -…
Data.Typeable 利用 Data.Typeable,可以打印动态类型信息. class Typeable (a :: k) where typeRep# :: TypeRep a typeRep :: Typeable a => TypeRep a typeRep = typeRep# typeOf :: Typeable a => a -> TypeRep a typeOf _ = typeRep typeOf 函数可以返回某个值的类型信息. {-# LANGUAGE Der…
安装 unordered-containers $ cabal install unordered-containers Installed unordered-containers-0.2.9.0 Prelude> import Data.HashSet as HashSet Prelude HashSet> :set -XOverloadedLists Prelude HashSet> Construction Prelude HashSet> empty fromList […
安装 unordered-containers $ cabal install unordered-containers Installed unordered-containers-0.2.9.0 Prelude> import Data.HashMap.Lazy as HashMap Prelude HashMap> :set -XOverloadedLists Prelude HashMap> Construction Prelude HashMap> empty fromL…
Data.Vector Construction Prelude V> import Data.Vector as V Prelude V> V.empty [] Prelude V> V.singleton 1 [1] Prelude V> V.replicate 5 1 [1,1,1,1,1] Prelude V> generate 5 (+1) [1,2,3,4,5] Prelude V> iterateN 5 (*2) 1 [1,2,4,8,16]…
Data.Set Prelude> import Data.Set as Set Prelude Set> :set -XOverloadedLists Construction Prelude Set> empty fromList [] Prelude Set> singleton 5 fromList [5] Prelude Set> insert 3 [4,5] fromList [3,4,5] Prelude Set> delete 5 [3,4,5] fro…
Data.Sequence Prelude> import Data.Sequence as Seq Prelude Seq> :set -XOverloadedLists Prelude Seq> Construction Prelude Seq> empty fromList [] Prelude Seq> singleton 3 fromList [3] Prelude Seq> 3 <| [4,5] fromList [3,4,5] Prelude Seq…