Created
May 25, 2010 09:16
-
-
Save inazt/412950 to your computer and use it in GitHub Desktop.
haskell02.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ghci> [1,2,3] | |
[1,2,3] | |
ghci> ["foo","bar","string"] | |
["foo","bar","string"] | |
ghci> [True,False] | |
[True,False] | |
-- enumeration notation | |
ghci> [1..5] | |
[1,2,3,4,5] | |
ghci> [True, False, "testing"] | |
<interactive>:1:14: | |
Couldn't match expected type `Bool' against inferred type `[Char]' | |
In the expression: "testing" | |
In the expression: [True, False, "testing"] | |
In the definition of `it': it = [True, False, "testing"] | |
-- no way to turn the string into a Boolean | |
ghci> [1,2,3] ++ [4,5] | |
[1,2,3,4,5] | |
ghci> 1:[2,3] | |
[1,2,3] | |
ghci> [2,3]:4 | |
<interactive>:1:6: | |
No instance for (Num [[t]]) | |
arising from the literal `4' at <interactive>:1:6 | |
Possible fix: add an instance declaration for (Num [[t]]) | |
In the second argument of `(:)', namely `4' | |
In the expression: [2, 3] : 4 | |
In the definition of `it': it = [2, 3] : 4 | |
-- error message, because the first argument of (:) must be an element, and the second must be a list. | |
-- String | |
ghci> "This is String \n newline" | |
"This is String \n newline" | |
ghci> "This is String '\n' newline" | |
"This is String '\n' newline" | |
ghci> put | |
putChar putStr putStrLn | |
ghci> putStr "This is String \n newline" | |
This is String | |
newlineghci> | |
ghci> let a = ['l', 'o', 't', 's', ' ', 'o', 'f', ' ', 'w', 'o', 'r', 'k'] | |
ghci> a | |
"lots of work" | |
ghci> a == "lots of work" | |
True | |
ghci> ['b','c'] | |
"bc" | |
ghci> | |
ghci> "" == [] | |
True | |
ghci> 'a':"bc" | |
"abc" | |
ghci> 'a':['b','c'] | |
"abc" | |
ghci> "bc":'a' | |
<interactive>:1:5: | |
Couldn't match expected type `[[Char]]' | |
against inferred type `Char' | |
In the second argument of `(:)', namely 'a' | |
In the expression: "bc" : 'a' | |
In the definition of `it': it = "bc" : 'a' | |
ghci> "abc"++"abc" | |
"abcabc" | |
ghci> ['a','b','c']++['a','b','c'] | |
"abcabc" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment