λ> import Data.Char λ> :t ord ord :: Char -> Int λ> :t chr chr :: Int -> Char λ> ord 'a' 97 λ> 5 + ord 'a' 102 λ> mod 30 26 4 λ> :t mod 30 26 mod 30 26 :: Integral a => a λ> fromInteg fromInteger fromIntegral λ> fromIntegral 5 5 λ> :t fromIntegral fromIntegral :: (Num b, Integral a) => a -> b λ> (read "5") + 1 6 λ> (read "[5,6]") ++ [7,8] [5,6,7,8] λ> :t (++) (++) :: [a] -> [a] -> [a] λ> (read "5") ++ [7,8] *** Exception: Prelude.read: no parse λ> :t read read :: Read a => String -> a λ> :t show show :: Show a => a -> String λ> :t fromRational fromRational :: Fractional a => Rational -> a λ> :t fromIntegral 5 fromIntegral 5 :: Num b => b λ> :t from fromEnum fromInteger fromIntegral fromRational λ> λ> λ> :i Integral class (Real a, Enum a) => Integral a where quot :: a -> a -> a rem :: a -> a -> a div :: a -> a -> a mod :: a -> a -> a quotRem :: a -> a -> (a, a) divMod :: a -> a -> (a, a) toInteger :: a -> Integer -- Defined in `GHC.Real' instance Integral Integer -- Defined in `GHC.Real' instance Integral Int -- Defined in `GHC.Real' λ> import Data.Word λ> :i Word8 data Word8 = GHC.Word.W8# GHC.Prim.Word# -- Defined in `GHC.Word' instance Bounded Word8 -- Defined in `GHC.Word' instance Enum Word8 -- Defined in `GHC.Word' instance Eq Word8 -- Defined in `GHC.Word' instance Integral Word8 -- Defined in `GHC.Word' instance Num Word8 -- Defined in `GHC.Word' instance Ord Word8 -- Defined in `GHC.Word' instance Read Word8 -- Defined in `GHC.Word' instance Real Word8 -- Defined in `GHC.Word' instance Show Word8 -- Defined in `GHC.Word' λ> ---------- varianta Tree de Int λ> :t Nil Nil :: Tree λ> :t Node Node :: Int -> [Tree] -> Tree λ> :i [] data [] a = [] | a : [a] -- Defined in `GHC.Types' instance Eq a => Eq [a] -- Defined in `GHC.Classes' instance Monad [] -- Defined in `GHC.Base' instance Functor [] -- Defined in `GHC.Base' instance Ord a => Ord [a] -- Defined in `GHC.Classes' instance Read a => Read [a] -- Defined in `GHC.Read' instance Show a => Show [a] -- Defined in `GHC.Show' λ> λ> --------- nu am dat argument în Node a [Tree] λ> λ> :r [1 of 1] Compiling Main ( PP-07-haskell-types-a.hs, interpreted ) PP-07-haskell-types-a.hs:68:43: Expecting one more argument to `Tree' Expected kind `*', but `Tree' has kind `* -> *' In the type `[Tree]' In the definition of data constructor `Node' In the data declaration for `Tree' Failed, modules loaded: none. λ> :kind Bool Bool :: * λ> :kind [] [] :: * -> * λ> :kind [Int] [Int] :: * λ> :i (->) data (->) a b -- Defined in `GHC.Prim' instance Monad ((->) r) -- Defined in `GHC.Base' instance Functor ((->) r) -- Defined in `GHC.Base' λ> :k (->) (->) :: * -> * -> * λ> λ> λ> λ> -- isNil cu == -- fără deriving Show isNil :: Eq (Tree a) => Tree a -> Bool λ> λ> --- cu deriving Show λ> :t isNil isNil :: Eq a => Tree a -> Bool λ> isNil Nil True λ> isNil $ Leaf 5 False ---- isNil cu pattern-matching λ> :t isNil isNil :: Tree t -> Bool λ> λ> λ> :t value value :: Tree t -> t λ> value tree1levels3 1 -- show din Haskell λ> tree1levels3 Node 1 [Node 1 [Leaf 1,Leaf 1],Node 1 [Leaf 1,Leaf 1]] -- show definit de mine λ> tree1levels3 1 1 1 1 1 1 1 λ> tree1 1 1 1 1 1 1 1 Interrupted. λ> :t show tree1 show tree1 :: String λ> take 200 $ show tree1 "1\n 1\n 1\n 1\n 1\n 1\n 1\n 1\n 1\n 1\n 1\n 1\n 1\n " λ> λ> λ> limit 5 $ tree1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 λ> :t undefined undefined :: a λ> :i undefined undefined :: a -- Defined in `GHC.Err' λ> undefined *** Exception: Prelude.undefined λ> value tree1 1 λ> head [] *** Exception: Prelude.head: empty list λ> limit 2 tree1levels3 1 1 1 -- limit cu trace λ> limit 2 tree1levels3 node 1 node 1 node 1 λ> tree1levels3 1 1 1 1 2 λ> limit 2 tree1levels3 node 1 node 1 otherwise 2 λ> preord tree1levels3 [1,1,1,1,2] λ> λ> limit 5 treeB 1 2 4 8 16 17 9 18 19 5 10 20 21 11 22 23 3 6 12 24 25 13 26 27 7 14 28 29 15 30 31 λ> preord $ limit 5 treeB [1,2,4,8,16,17,9,18,19,5,10,20,21,11,22,23,3,6,12,24,25,13,26,27,7,14,28,29,15,30,31] λ> PointC 2 3 PointC {px = 2.0, py = 3.0} λ> :t PointC 2 3 PointC 2 3 :: PointT λ> addP $ PointC 4 5 9.0 λ> px $ PointC 4 5 4.0 λ> py $ PointC 4 5 5.0 λ> :t px px :: PointT -> Double λ> ConstrD 5 ConstrD 5.0 λ> dx $ ConstrD 5 5.0 λ> px $ ConstrD 5 *** Exception: No match in record selector px λ> limit 5 $ 1 +> tree1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 λ> :i +> (+>) :: Num a => a -> Tree a -> Tree a -- Defined at PP-07-haskell-types-a.hs:153:1 λ> limit 5 $ 1 +> 1 +> tree1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 λ> limit 5 $ tree1 <+ 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 λ> limit 5 $ tree1 <+ 1 <+ 1 --- fără asociativitate :192:20: Couldn't match expected type `Integer' with actual type `Tree a1' In the second argument of `(<+)', namely `1 <+ 1' In the second argument of `($)', namely `tree1 <+ 1 <+ 1' In the expression: limit 5 $ tree1 <+ 1 <+ 1 -- cu asociativitate definită corect λ> limit 5 $ tree1 <+ 1 <+ 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -- cu aceeași precedență pentru +> și <+ λ> limit 5 $ 2 +> tree1 <+ 1 <+ 1 :195:1: Precedence parsing error cannot mix `+>' [infixr 5] and `<+' [infixl 5] in the same infix expression -- cu precendență diferită λ> limit 5 $ 2 +> tree1 <+ 1 <+ 1 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5