Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ++ and : in haskell?

Tags:

haskell

ghci

I don't get this--

Prelude> "hi"++"there"
"hithere"
Prelude> "hi":"there"

<interactive>:12:6:
    Couldn't match expected type `[Char]' with actual type `Char'
    Expected type: [[Char]]
      Actual type: [Char]
    In the second argument of `(:)', namely `"there"'
    In the expression: "hi" : "there"
Prelude> 

Why doesn't that also return "hithere"?

like image 638
Micah Avatar asked Nov 30 '22 02:11

Micah


1 Answers

The types. Try this in GCHi:

Prelude> :t (:)
(:) :: a -> [a] -> [a]
Prelude. :t (++)
(++) :: [a] -> [a] -> [a]
like image 152
Lily Ballard Avatar answered Dec 16 '22 01:12

Lily Ballard