TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Haskell: Let the Type Inferencer Work for You

26 pointsby msangiover 12 years ago

3 comments

crntaylorover 12 years ago
I don't get this line -- <i>"the Haskell compiler will complain because we still miss the definition of the type of the function."</i><p>That's not true. The compiler will give the function the most general type it can infer, which in this case is<p><pre><code> holds :: Eq a =&#62; UnionFindElement a -&#62; a -&#62; Bool </code></pre> without you needing to specify it in the file.<p>The <i>point</i> of the article is sound - using the interpreter to ask for types is a great way to work (and often leads to surprising realizations which can lead you to generalize and abstract your code), but the <i>reasoning</i> is spurious. Most of the time, you don't need to supply types in Haskell, as the compiler is perfectly capable of figuring them out for itself.
评论 #4933661 未加载
评论 #4933213 未加载
评论 #4933090 未加载
gtaniover 12 years ago
More on how much GHC (and other compilers) can reason about resources (alternatively:infer/thorem prove from type signatures and knowledge about data structures used:<p><a href="http://stackoverflow.com/questions/11725899/is-there-a-theory-that-combines-category-theory-abstract-algebra-and-computation" rel="nofollow">http://stackoverflow.com/questions/11725899/is-there-a-theor...</a><p><a href="http://homepages.inf.ed.ac.uk/bcampbe2/thesis/thesis-final.pdf" rel="nofollow">http://homepages.inf.ed.ac.uk/bcampbe2/thesis/thesis-final.p...</a><p><a href="http://research-repository.st-andrews.ac.uk/bitstream/10023/564/6/Pedro%20B%20Vasconcelos%20PhD%20thesis.pdf" rel="nofollow">http://research-repository.st-andrews.ac.uk/bitstream/10023/...</a><p><a href="http://www.cs.cmu.edu/~rwh/papers/iolambda/short.pdf" rel="nofollow">http://www.cs.cmu.edu/~rwh/papers/iolambda/short.pdf</a><p>Also, there's djinn
评论 #4933436 未加载
评论 #4933547 未加载
loqiover 12 years ago
You can also get type signatures non-interactively with ghc's -ddump-types flag.