Type inference
From HaskellWiki
(Difference between revisions)
(explanation with example) |
(wikipedia links) |
||
| Line 19: | Line 19: | ||
== See also == | == See also == | ||
| - | The type inference mechanism is very similar to [http://en.wikipedia.org/Unification unification] in [http://en.wikipedia.org/PROLOG PROLOG]. | + | The type inference mechanism is very similar to [http://en.wikipedia.org/wiki/Unification unification] in [http://en.wikipedia.org/wiki/PROLOG PROLOG]. |
* Haskell-Cafe: [http://www.haskell.org/pipermail/haskell-cafe/2007-September/031255.html Learn Prolog ...] | * Haskell-Cafe: [http://www.haskell.org/pipermail/haskell-cafe/2007-September/031255.html Learn Prolog ...] | ||
[[Category:Glossary]] | [[Category:Glossary]] | ||
Current revision
Type inference is a feature of the type system which means that concrete types are deduced by the type system whereever it is obvious.
If you add an integer variablex
2
2
+
(This restriction is a good thing, as we explain for the idea of a Generic number type.)
Another example: There are the following standard functions:
map :: (a -> b) -> [a] -> [b] Char.ord :: (Char -> Int)
map ord
a
Char
b
Int
map ord :: [Char] -> [Int]
You can play with the type inference mechanism in Hugs and GHCi. See Determining the type of an expression.
See also
The type inference mechanism is very similar to unification in PROLOG.
- Haskell-Cafe: Learn Prolog ...
