CINXE.COM

Type inference - Wikipedia

<!DOCTYPE html> <html class="client-nojs vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-sticky-header-enabled vector-toc-available" lang="en" dir="ltr"> <head> <meta charset="UTF-8"> <title>Type inference - Wikipedia</title> <script>(function(){var className="client-js vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-feature-night-mode-enabled skin-theme-clientpref-day vector-sticky-header-enabled vector-toc-available";var cookie=document.cookie.match(/(?:^|; )enwikimwclientpreferences=([^;]+)/);if(cookie){cookie[1].split('%2C').forEach(function(pref){className=className.replace(new RegExp('(^| )'+pref.replace(/-clientpref-\w+$|[^\w-]+/g,'')+'-clientpref-\\w+( |$)'),'$1'+pref+'$2');});}document.documentElement.className=className;}());RLCONF={"wgBreakFrames":false,"wgSeparatorTransformTable":["",""],"wgDigitTransformTable":["",""],"wgDefaultDateFormat":"dmy","wgMonthNames":["","January","February","March","April","May","June","July","August","September","October","November","December"],"wgRequestId":"72553c3f-01e9-49c7-8d5e-057272f052e7","wgCanonicalNamespace":"","wgCanonicalSpecialPageName":false,"wgNamespaceNumber":0,"wgPageName":"Type_inference","wgTitle":"Type inference","wgCurRevisionId":1238605275,"wgRevisionId":1238605275,"wgArticleId":279690,"wgIsArticle":true,"wgIsRedirect":false,"wgAction":"view","wgUserName":null,"wgUserGroups":["*"],"wgCategories":["Webarchive template wayback links","Articles with short description","Short description is different from Wikidata","Articles needing additional references from November 2020","All articles needing additional references","All articles with unsourced statements","Articles with unsourced statements from February 2021","Articles with example C code","Articles with example Haskell code","Articles with example JavaScript code","Type inference","Type systems","Type theory","Inference"],"wgPageViewLanguage":"en","wgPageContentLanguage":"en","wgPageContentModel":"wikitext","wgRelevantPageName":"Type_inference","wgRelevantArticleId":279690,"wgIsProbablyEditable":true,"wgRelevantPageIsProbablyEditable":true,"wgRestrictionEdit":[],"wgRestrictionMove":[],"wgNoticeProject":"wikipedia","wgCiteReferencePreviewsActive":false,"wgFlaggedRevsParams":{"tags":{"status":{"levels":1}}},"wgMediaViewerOnClick":true,"wgMediaViewerEnabledByDefault":true,"wgPopupsFlags":0,"wgVisualEditor":{"pageLanguageCode":"en","pageLanguageDir":"ltr","pageVariantFallbacks":"en"},"wgMFDisplayWikibaseDescriptions":{"search":true,"watchlist":true,"tagline":false,"nearby":true},"wgWMESchemaEditAttemptStepOversample":false,"wgWMEPageLength":30000,"wgEditSubmitButtonLabelPublish":true,"wgULSPosition":"interlanguage","wgULSisCompactLinksEnabled":false,"wgVector2022LanguageInHeader":true,"wgULSisLanguageSelectorEmpty":false,"wgWikibaseItemId":"Q586459","wgCheckUserClientHintsHeadersJsApi":["brands","architecture","bitness","fullVersionList","mobile","model","platform","platformVersion"],"GEHomepageSuggestedEditsEnableTopics":true,"wgGETopicsMatchModeEnabled":false,"wgGEStructuredTaskRejectionReasonTextInputEnabled":false,"wgGELevelingUpEnabledForUser":false}; RLSTATE={"ext.globalCssJs.user.styles":"ready","site.styles":"ready","user.styles":"ready","ext.globalCssJs.user":"ready","user":"ready","user.options":"loading","ext.cite.styles":"ready","ext.pygments":"ready","skins.vector.search.codex.styles":"ready","skins.vector.styles":"ready","skins.vector.icons":"ready","ext.wikimediamessages.styles":"ready","ext.visualEditor.desktopArticleTarget.noscript":"ready","ext.uls.interlanguage":"ready","wikibase.client.init":"ready"};RLPAGEMODULES=["ext.cite.ux-enhancements","ext.pygments.view","site","mediawiki.page.ready","mediawiki.toc","skins.vector.js","ext.centralNotice.geoIP","ext.centralNotice.startUp","ext.gadget.ReferenceTooltips","ext.gadget.switcher","ext.urlShortener.toolbar","ext.centralauth.centralautologin","mmv.bootstrap","ext.popups","ext.visualEditor.desktopArticleTarget.init","ext.visualEditor.targetLoader","ext.echo.centralauth","ext.eventLogging","ext.wikimediaEvents","ext.navigationTiming","ext.uls.interface","ext.cx.eventlogging.campaigns","ext.cx.uls.quick.actions","wikibase.client.vector-2022","ext.checkUser.clientHints","ext.growthExperiments.SuggestedEditSession"];</script> <script>(RLQ=window.RLQ||[]).push(function(){mw.loader.impl(function(){return["user.options@12s5i",function($,jQuery,require,module){mw.user.tokens.set({"patrolToken":"+\\","watchToken":"+\\","csrfToken":"+\\"}); }];});});</script> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=ext.cite.styles%7Cext.pygments%7Cext.uls.interlanguage%7Cext.visualEditor.desktopArticleTarget.noscript%7Cext.wikimediamessages.styles%7Cskins.vector.icons%2Cstyles%7Cskins.vector.search.codex.styles%7Cwikibase.client.init&amp;only=styles&amp;skin=vector-2022"> <script async="" src="/w/load.php?lang=en&amp;modules=startup&amp;only=scripts&amp;raw=1&amp;skin=vector-2022"></script> <meta name="ResourceLoaderDynamicStyles" content=""> <link rel="stylesheet" href="/w/load.php?lang=en&amp;modules=site.styles&amp;only=styles&amp;skin=vector-2022"> <meta name="generator" content="MediaWiki 1.44.0-wmf.19"> <meta name="referrer" content="origin"> <meta name="referrer" content="origin-when-cross-origin"> <meta name="robots" content="max-image-preview:standard"> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="width=1120"> <meta property="og:title" content="Type inference - Wikipedia"> <meta property="og:type" content="website"> <link rel="preconnect" href="//upload.wikimedia.org"> <link rel="alternate" media="only screen and (max-width: 640px)" href="//en.m.wikipedia.org/wiki/Type_inference"> <link rel="alternate" type="application/x-wiki" title="Edit this page" href="/w/index.php?title=Type_inference&amp;action=edit"> <link rel="apple-touch-icon" href="/static/apple-touch/wikipedia.png"> <link rel="icon" href="/static/favicon/wikipedia.ico"> <link rel="search" type="application/opensearchdescription+xml" href="/w/rest.php/v1/search" title="Wikipedia (en)"> <link rel="EditURI" type="application/rsd+xml" href="//en.wikipedia.org/w/api.php?action=rsd"> <link rel="canonical" href="https://en.wikipedia.org/wiki/Type_inference"> <link rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en"> <link rel="alternate" type="application/atom+xml" title="Wikipedia Atom feed" href="/w/index.php?title=Special:RecentChanges&amp;feed=atom"> <link rel="dns-prefetch" href="//meta.wikimedia.org" /> <link rel="dns-prefetch" href="login.wikimedia.org"> </head> <body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject mw-editable page-Type_inference rootpage-Type_inference skin-vector-2022 action-view"><a class="mw-jump-link" href="#bodyContent">Jump to content</a> <div class="vector-header-container"> <header class="vector-header mw-header"> <div class="vector-header-start"> <nav class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-dropdown" class="vector-dropdown vector-main-menu-dropdown vector-button-flush-left vector-button-flush-right" title="Main menu" > <input type="checkbox" id="vector-main-menu-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-main-menu-dropdown" class="vector-dropdown-checkbox " aria-label="Main menu" > <label id="vector-main-menu-dropdown-label" for="vector-main-menu-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-menu mw-ui-icon-wikimedia-menu"></span> <span class="vector-dropdown-label-text">Main menu</span> </label> <div class="vector-dropdown-content"> <div id="vector-main-menu-unpinned-container" class="vector-unpinned-container"> <div id="vector-main-menu" class="vector-main-menu vector-pinnable-element"> <div class="vector-pinnable-header vector-main-menu-pinnable-header vector-pinnable-header-unpinned" data-feature-name="main-menu-pinned" data-pinnable-element-id="vector-main-menu" data-pinned-container-id="vector-main-menu-pinned-container" data-unpinned-container-id="vector-main-menu-unpinned-container" > <div class="vector-pinnable-header-label">Main menu</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-main-menu.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-main-menu.unpin">hide</button> </div> <div id="p-navigation" class="vector-menu mw-portlet mw-portlet-navigation" > <div class="vector-menu-heading"> Navigation </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-mainpage-description" class="mw-list-item"><a href="/wiki/Main_Page" title="Visit the main page [z]" accesskey="z"><span>Main page</span></a></li><li id="n-contents" class="mw-list-item"><a href="/wiki/Wikipedia:Contents" title="Guides to browsing Wikipedia"><span>Contents</span></a></li><li id="n-currentevents" class="mw-list-item"><a href="/wiki/Portal:Current_events" title="Articles related to current events"><span>Current events</span></a></li><li id="n-randompage" class="mw-list-item"><a href="/wiki/Special:Random" title="Visit a randomly selected article [x]" accesskey="x"><span>Random article</span></a></li><li id="n-aboutsite" class="mw-list-item"><a href="/wiki/Wikipedia:About" title="Learn about Wikipedia and how it works"><span>About Wikipedia</span></a></li><li id="n-contactpage" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us" title="How to contact Wikipedia"><span>Contact us</span></a></li> </ul> </div> </div> <div id="p-interaction" class="vector-menu mw-portlet mw-portlet-interaction" > <div class="vector-menu-heading"> Contribute </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="n-help" class="mw-list-item"><a href="/wiki/Help:Contents" title="Guidance on how to use and edit Wikipedia"><span>Help</span></a></li><li id="n-introduction" class="mw-list-item"><a href="/wiki/Help:Introduction" title="Learn how to edit Wikipedia"><span>Learn to edit</span></a></li><li id="n-portal" class="mw-list-item"><a href="/wiki/Wikipedia:Community_portal" title="The hub for editors"><span>Community portal</span></a></li><li id="n-recentchanges" class="mw-list-item"><a href="/wiki/Special:RecentChanges" title="A list of recent changes to Wikipedia [r]" accesskey="r"><span>Recent changes</span></a></li><li id="n-upload" class="mw-list-item"><a href="/wiki/Wikipedia:File_upload_wizard" title="Add images or other media for use on Wikipedia"><span>Upload file</span></a></li><li id="n-specialpages" class="mw-list-item"><a href="/wiki/Special:SpecialPages"><span>Special pages</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> <a href="/wiki/Main_Page" class="mw-logo"> <img class="mw-logo-icon" src="/static/images/icons/wikipedia.png" alt="" aria-hidden="true" height="50" width="50"> <span class="mw-logo-container skin-invert"> <img class="mw-logo-wordmark" alt="Wikipedia" src="/static/images/mobile/copyright/wikipedia-wordmark-en.svg" style="width: 7.5em; height: 1.125em;"> <img class="mw-logo-tagline" alt="The Free Encyclopedia" src="/static/images/mobile/copyright/wikipedia-tagline-en.svg" width="117" height="13" style="width: 7.3125em; height: 0.8125em;"> </span> </a> </div> <div class="vector-header-end"> <div id="p-search" role="search" class="vector-search-box-vue vector-search-box-collapses vector-search-box-show-thumbnail vector-search-box-auto-expand-width vector-search-box"> <a href="/wiki/Special:Search" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only search-toggle" title="Search Wikipedia [f]" accesskey="f"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </a> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail cdx-typeahead-search--auto-expand-width"> <form action="/w/index.php" id="searchform" class="cdx-search-input cdx-search-input--has-end-button"> <div id="simpleSearch" class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikipedia" aria-label="Search Wikipedia" autocapitalize="sentences" title="Search Wikipedia [f]" accesskey="f" id="searchInput" > <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <nav class="vector-user-links vector-user-links-wide" aria-label="Personal tools"> <div class="vector-user-links-main"> <div id="p-vector-user-menu-preferences" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-userpage" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-dropdown" class="vector-dropdown " title="Change the appearance of the page&#039;s font size, width, and color" > <input type="checkbox" id="vector-appearance-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-appearance-dropdown" class="vector-dropdown-checkbox " aria-label="Appearance" > <label id="vector-appearance-dropdown-label" for="vector-appearance-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-appearance mw-ui-icon-wikimedia-appearance"></span> <span class="vector-dropdown-label-text">Appearance</span> </label> <div class="vector-dropdown-content"> <div id="vector-appearance-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div id="p-vector-user-menu-notifications" class="vector-menu mw-portlet emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> <div id="p-vector-user-menu-overflow" class="vector-menu mw-portlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="https://donate.wikimedia.org/?wmf_source=donate&amp;wmf_medium=sidebar&amp;wmf_campaign=en.wikipedia.org&amp;uselang=en" class=""><span>Donate</span></a> </li> <li id="pt-createaccount-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:CreateAccount&amp;returnto=Type+inference" title="You are encouraged to create an account and log in; however, it is not mandatory" class=""><span>Create account</span></a> </li> <li id="pt-login-2" class="user-links-collapsible-item mw-list-item user-links-collapsible-item"><a data-mw="interface" href="/w/index.php?title=Special:UserLogin&amp;returnto=Type+inference" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o" class=""><span>Log in</span></a> </li> </ul> </div> </div> </div> <div id="vector-user-links-dropdown" class="vector-dropdown vector-user-menu vector-button-flush-right vector-user-menu-logged-out" title="Log in and more options" > <input type="checkbox" id="vector-user-links-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-user-links-dropdown" class="vector-dropdown-checkbox " aria-label="Personal tools" > <label id="vector-user-links-dropdown-label" for="vector-user-links-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-ellipsis mw-ui-icon-wikimedia-ellipsis"></span> <span class="vector-dropdown-label-text">Personal tools</span> </label> <div class="vector-dropdown-content"> <div id="p-personal" class="vector-menu mw-portlet mw-portlet-personal user-links-collapsible-item" title="User menu" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-sitesupport" class="user-links-collapsible-item mw-list-item"><a href="https://donate.wikimedia.org/?wmf_source=donate&amp;wmf_medium=sidebar&amp;wmf_campaign=en.wikipedia.org&amp;uselang=en"><span>Donate</span></a></li><li id="pt-createaccount" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:CreateAccount&amp;returnto=Type+inference" title="You are encouraged to create an account and log in; however, it is not mandatory"><span class="vector-icon mw-ui-icon-userAdd mw-ui-icon-wikimedia-userAdd"></span> <span>Create account</span></a></li><li id="pt-login" class="user-links-collapsible-item mw-list-item"><a href="/w/index.php?title=Special:UserLogin&amp;returnto=Type+inference" title="You&#039;re encouraged to log in; however, it&#039;s not mandatory. [o]" accesskey="o"><span class="vector-icon mw-ui-icon-logIn mw-ui-icon-wikimedia-logIn"></span> <span>Log in</span></a></li> </ul> </div> </div> <div id="p-user-menu-anon-editor" class="vector-menu mw-portlet mw-portlet-user-menu-anon-editor" > <div class="vector-menu-heading"> Pages for logged out editors <a href="/wiki/Help:Introduction" aria-label="Learn more about editing"><span>learn more</span></a> </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="pt-anoncontribs" class="mw-list-item"><a href="/wiki/Special:MyContributions" title="A list of edits made from this IP address [y]" accesskey="y"><span>Contributions</span></a></li><li id="pt-anontalk" class="mw-list-item"><a href="/wiki/Special:MyTalk" title="Discussion about edits from this IP address [n]" accesskey="n"><span>Talk</span></a></li> </ul> </div> </div> </div> </div> </nav> </div> </header> </div> <div class="mw-page-container"> <div class="mw-page-container-inner"> <div class="vector-sitenotice-container"> <div id="siteNotice"><!-- CentralNotice --></div> </div> <div class="vector-column-start"> <div class="vector-main-menu-container"> <div id="mw-navigation"> <nav id="mw-panel" class="vector-main-menu-landmark" aria-label="Site"> <div id="vector-main-menu-pinned-container" class="vector-pinned-container"> </div> </nav> </div> </div> <div class="vector-sticky-pinned-container"> <nav id="mw-panel-toc" aria-label="Contents" data-event-name="ui.sidebar-toc" class="mw-table-of-contents-container vector-toc-landmark"> <div id="vector-toc-pinned-container" class="vector-pinned-container"> <div id="vector-toc" class="vector-toc vector-pinnable-element"> <div class="vector-pinnable-header vector-toc-pinnable-header vector-pinnable-header-pinned" data-feature-name="toc-pinned" data-pinnable-element-id="vector-toc" > <h2 class="vector-pinnable-header-label">Contents</h2> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-toc.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-toc.unpin">hide</button> </div> <ul class="vector-toc-contents" id="mw-panel-toc-list"> <li id="toc-mw-content-text" class="vector-toc-list-item vector-toc-level-1"> <a href="#" class="vector-toc-link"> <div class="vector-toc-text">(Top)</div> </a> </li> <li id="toc-Nontechnical_explanation" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Nontechnical_explanation"> <div class="vector-toc-text"> <span class="vector-toc-numb">1</span> <span>Nontechnical explanation</span> </div> </a> <ul id="toc-Nontechnical_explanation-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Type-checking_vs._type-inference" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Type-checking_vs._type-inference"> <div class="vector-toc-text"> <span class="vector-toc-numb">2</span> <span>Type-checking vs. type-inference</span> </div> </a> <ul id="toc-Type-checking_vs._type-inference-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Types_in_programming_languages" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Types_in_programming_languages"> <div class="vector-toc-text"> <span class="vector-toc-numb">3</span> <span>Types in programming languages</span> </div> </a> <ul id="toc-Types_in_programming_languages-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Technical_description" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Technical_description"> <div class="vector-toc-text"> <span class="vector-toc-numb">4</span> <span>Technical description</span> </div> </a> <ul id="toc-Technical_description-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-High-Level_Example" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#High-Level_Example"> <div class="vector-toc-text"> <span class="vector-toc-numb">5</span> <span>High-Level Example</span> </div> </a> <ul id="toc-High-Level_Example-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Detailed_Example" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Detailed_Example"> <div class="vector-toc-text"> <span class="vector-toc-numb">6</span> <span>Detailed Example</span> </div> </a> <ul id="toc-Detailed_Example-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Hindley–Milner_type_inference_algorithm" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Hindley–Milner_type_inference_algorithm"> <div class="vector-toc-text"> <span class="vector-toc-numb">7</span> <span>Hindley–Milner type inference algorithm</span> </div> </a> <ul id="toc-Hindley–Milner_type_inference_algorithm-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Side-effects_of_using_the_most_general_type" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Side-effects_of_using_the_most_general_type"> <div class="vector-toc-text"> <span class="vector-toc-numb">8</span> <span>Side-effects of using the most general type</span> </div> </a> <ul id="toc-Side-effects_of_using_the_most_general_type-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-Type_inference_for_natural_languages" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#Type_inference_for_natural_languages"> <div class="vector-toc-text"> <span class="vector-toc-numb">9</span> <span>Type inference for natural languages</span> </div> </a> <ul id="toc-Type_inference_for_natural_languages-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-References" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#References"> <div class="vector-toc-text"> <span class="vector-toc-numb">10</span> <span>References</span> </div> </a> <ul id="toc-References-sublist" class="vector-toc-list"> </ul> </li> <li id="toc-External_links" class="vector-toc-list-item vector-toc-level-1 vector-toc-list-item-expanded"> <a class="vector-toc-link" href="#External_links"> <div class="vector-toc-text"> <span class="vector-toc-numb">11</span> <span>External links</span> </div> </a> <ul id="toc-External_links-sublist" class="vector-toc-list"> </ul> </li> </ul> </div> </div> </nav> </div> </div> <div class="mw-content-container"> <main id="content" class="mw-body"> <header class="mw-body-header vector-page-titlebar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-page-titlebar-toc" class="vector-dropdown vector-page-titlebar-toc vector-button-flush-left" title="Table of Contents" > <input type="checkbox" id="vector-page-titlebar-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-titlebar-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-page-titlebar-toc-label" for="vector-page-titlebar-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-titlebar-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <h1 id="firstHeading" class="firstHeading mw-first-heading"><span class="mw-page-title-main">Type inference</span></h1> <div id="p-lang-btn" class="vector-dropdown mw-portlet mw-portlet-lang" > <input type="checkbox" id="p-lang-btn-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-lang-btn" class="vector-dropdown-checkbox mw-interlanguage-selector" aria-label="Go to an article in another language. Available in 16 languages" > <label id="p-lang-btn-label" for="p-lang-btn-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive mw-portlet-lang-heading-16" aria-hidden="true" ><span class="vector-icon mw-ui-icon-language-progressive mw-ui-icon-wikimedia-language-progressive"></span> <span class="vector-dropdown-label-text">16 languages</span> </label> <div class="vector-dropdown-content"> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li class="interlanguage-link interwiki-cs mw-list-item"><a href="https://cs.wikipedia.org/wiki/Typov%C3%A1_inference" title="Typová inference – Czech" lang="cs" hreflang="cs" data-title="Typová inference" data-language-autonym="Čeština" data-language-local-name="Czech" class="interlanguage-link-target"><span>Čeština</span></a></li><li class="interlanguage-link interwiki-de mw-list-item"><a href="https://de.wikipedia.org/wiki/Typinferenz" title="Typinferenz – German" lang="de" hreflang="de" data-title="Typinferenz" data-language-autonym="Deutsch" data-language-local-name="German" class="interlanguage-link-target"><span>Deutsch</span></a></li><li class="interlanguage-link interwiki-el mw-list-item"><a href="https://el.wikipedia.org/wiki/%CE%95%CE%BE%CE%B1%CE%B3%CF%89%CE%B3%CE%AE_%CF%84%CF%8D%CF%80%CF%89%CE%BD" title="Εξαγωγή τύπων – Greek" lang="el" hreflang="el" data-title="Εξαγωγή τύπων" data-language-autonym="Ελληνικά" data-language-local-name="Greek" class="interlanguage-link-target"><span>Ελληνικά</span></a></li><li class="interlanguage-link interwiki-es mw-list-item"><a href="https://es.wikipedia.org/wiki/Inferencia_de_tipos" title="Inferencia de tipos – Spanish" lang="es" hreflang="es" data-title="Inferencia de tipos" data-language-autonym="Español" data-language-local-name="Spanish" class="interlanguage-link-target"><span>Español</span></a></li><li class="interlanguage-link interwiki-fa mw-list-item"><a href="https://fa.wikipedia.org/wiki/%D8%A7%D8%B3%D8%AA%D9%86%D8%A8%D8%A7%D8%B7_%D9%86%D9%88%D8%B9" title="استنباط نوع – Persian" lang="fa" hreflang="fa" data-title="استنباط نوع" data-language-autonym="فارسی" data-language-local-name="Persian" class="interlanguage-link-target"><span>فارسی</span></a></li><li class="interlanguage-link interwiki-fr mw-list-item"><a href="https://fr.wikipedia.org/wiki/Inf%C3%A9rence_de_types" title="Inférence de types – French" lang="fr" hreflang="fr" data-title="Inférence de types" data-language-autonym="Français" data-language-local-name="French" class="interlanguage-link-target"><span>Français</span></a></li><li class="interlanguage-link interwiki-hu mw-list-item"><a href="https://hu.wikipedia.org/wiki/T%C3%ADpusk%C3%B6vetkeztet%C3%A9s" title="Típuskövetkeztetés – Hungarian" lang="hu" hreflang="hu" data-title="Típuskövetkeztetés" data-language-autonym="Magyar" data-language-local-name="Hungarian" class="interlanguage-link-target"><span>Magyar</span></a></li><li class="interlanguage-link interwiki-ms mw-list-item"><a href="https://ms.wikipedia.org/wiki/Inferens_jenis" title="Inferens jenis – Malay" lang="ms" hreflang="ms" data-title="Inferens jenis" data-language-autonym="Bahasa Melayu" data-language-local-name="Malay" class="interlanguage-link-target"><span>Bahasa Melayu</span></a></li><li class="interlanguage-link interwiki-nl mw-list-item"><a href="https://nl.wikipedia.org/wiki/Type-inferentie" title="Type-inferentie – Dutch" lang="nl" hreflang="nl" data-title="Type-inferentie" data-language-autonym="Nederlands" data-language-local-name="Dutch" class="interlanguage-link-target"><span>Nederlands</span></a></li><li class="interlanguage-link interwiki-ja mw-list-item"><a href="https://ja.wikipedia.org/wiki/%E5%9E%8B%E6%8E%A8%E8%AB%96" title="型推論 – Japanese" lang="ja" hreflang="ja" data-title="型推論" data-language-autonym="日本語" data-language-local-name="Japanese" class="interlanguage-link-target"><span>日本語</span></a></li><li class="interlanguage-link interwiki-pl mw-list-item"><a href="https://pl.wikipedia.org/wiki/Inferencja_typ%C3%B3w" title="Inferencja typów – Polish" lang="pl" hreflang="pl" data-title="Inferencja typów" data-language-autonym="Polski" data-language-local-name="Polish" class="interlanguage-link-target"><span>Polski</span></a></li><li class="interlanguage-link interwiki-ru mw-list-item"><a href="https://ru.wikipedia.org/wiki/%D0%92%D1%8B%D0%B2%D0%BE%D0%B4_%D1%82%D0%B8%D0%BF%D0%BE%D0%B2" title="Вывод типов – Russian" lang="ru" hreflang="ru" data-title="Вывод типов" data-language-autonym="Русский" data-language-local-name="Russian" class="interlanguage-link-target"><span>Русский</span></a></li><li class="interlanguage-link interwiki-tr mw-list-item"><a href="https://tr.wikipedia.org/wiki/Tip_belirleme" title="Tip belirleme – Turkish" lang="tr" hreflang="tr" data-title="Tip belirleme" data-language-autonym="Türkçe" data-language-local-name="Turkish" class="interlanguage-link-target"><span>Türkçe</span></a></li><li class="interlanguage-link interwiki-uk mw-list-item"><a href="https://uk.wikipedia.org/wiki/%D0%92%D0%B8%D0%B2%D1%96%D0%B4_%D1%82%D0%B8%D0%BF%D1%96%D0%B2" title="Вивід типів – Ukrainian" lang="uk" hreflang="uk" data-title="Вивід типів" data-language-autonym="Українська" data-language-local-name="Ukrainian" class="interlanguage-link-target"><span>Українська</span></a></li><li class="interlanguage-link interwiki-vi mw-list-item"><a href="https://vi.wikipedia.org/wiki/Suy_lu%E1%BA%ADn_ki%E1%BB%83u" title="Suy luận kiểu – Vietnamese" lang="vi" hreflang="vi" data-title="Suy luận kiểu" data-language-autonym="Tiếng Việt" data-language-local-name="Vietnamese" class="interlanguage-link-target"><span>Tiếng Việt</span></a></li><li class="interlanguage-link interwiki-zh mw-list-item"><a href="https://zh.wikipedia.org/wiki/%E7%B1%BB%E5%9E%8B%E6%8E%A8%E8%AE%BA" title="类型推论 – Chinese" lang="zh" hreflang="zh" data-title="类型推论" data-language-autonym="中文" data-language-local-name="Chinese" class="interlanguage-link-target"><span>中文</span></a></li> </ul> <div class="after-portlet after-portlet-lang"><span class="wb-langlinks-edit wb-langlinks-link"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q586459#sitelinks-wikipedia" title="Edit interlanguage links" class="wbc-editpage">Edit links</a></span></div> </div> </div> </div> </header> <div class="vector-page-toolbar"> <div class="vector-page-toolbar-container"> <div id="left-navigation"> <nav aria-label="Namespaces"> <div id="p-associated-pages" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-associated-pages" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-nstab-main" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Type_inference" title="View the content page [c]" accesskey="c"><span>Article</span></a></li><li id="ca-talk" class="vector-tab-noicon mw-list-item"><a href="/wiki/Talk:Type_inference" rel="discussion" title="Discuss improvements to the content page [t]" accesskey="t"><span>Talk</span></a></li> </ul> </div> </div> <div id="vector-variants-dropdown" class="vector-dropdown emptyPortlet" > <input type="checkbox" id="vector-variants-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-variants-dropdown" class="vector-dropdown-checkbox " aria-label="Change language variant" > <label id="vector-variants-dropdown-label" for="vector-variants-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">English</span> </label> <div class="vector-dropdown-content"> <div id="p-variants" class="vector-menu mw-portlet mw-portlet-variants emptyPortlet" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> </ul> </div> </div> </div> </div> </nav> </div> <div id="right-navigation" class="vector-collapsible"> <nav aria-label="Views"> <div id="p-views" class="vector-menu vector-menu-tabs mw-portlet mw-portlet-views" > <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-view" class="selected vector-tab-noicon mw-list-item"><a href="/wiki/Type_inference"><span>Read</span></a></li><li id="ca-edit" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Type_inference&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-history" class="vector-tab-noicon mw-list-item"><a href="/w/index.php?title=Type_inference&amp;action=history" title="Past revisions of this page [h]" accesskey="h"><span>View history</span></a></li> </ul> </div> </div> </nav> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-dropdown" class="vector-dropdown vector-page-tools-dropdown" > <input type="checkbox" id="vector-page-tools-dropdown-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-page-tools-dropdown" class="vector-dropdown-checkbox " aria-label="Tools" > <label id="vector-page-tools-dropdown-label" for="vector-page-tools-dropdown-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet" aria-hidden="true" ><span class="vector-dropdown-label-text">Tools</span> </label> <div class="vector-dropdown-content"> <div id="vector-page-tools-unpinned-container" class="vector-unpinned-container"> <div id="vector-page-tools" class="vector-page-tools vector-pinnable-element"> <div class="vector-pinnable-header vector-page-tools-pinnable-header vector-pinnable-header-unpinned" data-feature-name="page-tools-pinned" data-pinnable-element-id="vector-page-tools" data-pinned-container-id="vector-page-tools-pinned-container" data-unpinned-container-id="vector-page-tools-unpinned-container" > <div class="vector-pinnable-header-label">Tools</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-page-tools.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-page-tools.unpin">hide</button> </div> <div id="p-cactions" class="vector-menu mw-portlet mw-portlet-cactions emptyPortlet vector-has-collapsible-items" title="More options" > <div class="vector-menu-heading"> Actions </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="ca-more-view" class="selected vector-more-collapsible-item mw-list-item"><a href="/wiki/Type_inference"><span>Read</span></a></li><li id="ca-more-edit" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Type_inference&amp;action=edit" title="Edit this page [e]" accesskey="e"><span>Edit</span></a></li><li id="ca-more-history" class="vector-more-collapsible-item mw-list-item"><a href="/w/index.php?title=Type_inference&amp;action=history"><span>View history</span></a></li> </ul> </div> </div> <div id="p-tb" class="vector-menu mw-portlet mw-portlet-tb" > <div class="vector-menu-heading"> General </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-whatlinkshere" class="mw-list-item"><a href="/wiki/Special:WhatLinksHere/Type_inference" title="List of all English Wikipedia pages containing links to this page [j]" accesskey="j"><span>What links here</span></a></li><li id="t-recentchangeslinked" class="mw-list-item"><a href="/wiki/Special:RecentChangesLinked/Type_inference" rel="nofollow" title="Recent changes in pages linked from this page [k]" accesskey="k"><span>Related changes</span></a></li><li id="t-upload" class="mw-list-item"><a href="//en.wikipedia.org/wiki/Wikipedia:File_Upload_Wizard" title="Upload files [u]" accesskey="u"><span>Upload file</span></a></li><li id="t-permalink" class="mw-list-item"><a href="/w/index.php?title=Type_inference&amp;oldid=1238605275" title="Permanent link to this revision of this page"><span>Permanent link</span></a></li><li id="t-info" class="mw-list-item"><a href="/w/index.php?title=Type_inference&amp;action=info" title="More information about this page"><span>Page information</span></a></li><li id="t-cite" class="mw-list-item"><a href="/w/index.php?title=Special:CiteThisPage&amp;page=Type_inference&amp;id=1238605275&amp;wpFormIdentifier=titleform" title="Information on how to cite this page"><span>Cite this page</span></a></li><li id="t-urlshortener" class="mw-list-item"><a href="/w/index.php?title=Special:UrlShortener&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FType_inference"><span>Get shortened URL</span></a></li><li id="t-urlshortener-qrcode" class="mw-list-item"><a href="/w/index.php?title=Special:QrCode&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FType_inference"><span>Download QR code</span></a></li> </ul> </div> </div> <div id="p-coll-print_export" class="vector-menu mw-portlet mw-portlet-coll-print_export" > <div class="vector-menu-heading"> Print/export </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="coll-download-as-rl" class="mw-list-item"><a href="/w/index.php?title=Special:DownloadAsPdf&amp;page=Type_inference&amp;action=show-download-screen" title="Download this page as a PDF file"><span>Download as PDF</span></a></li><li id="t-print" class="mw-list-item"><a href="/w/index.php?title=Type_inference&amp;printable=yes" title="Printable version of this page [p]" accesskey="p"><span>Printable version</span></a></li> </ul> </div> </div> <div id="p-wikibase-otherprojects" class="vector-menu mw-portlet mw-portlet-wikibase-otherprojects" > <div class="vector-menu-heading"> In other projects </div> <div class="vector-menu-content"> <ul class="vector-menu-content-list"> <li id="t-wikibase" class="wb-otherproject-link wb-otherproject-wikibase-dataitem mw-list-item"><a href="https://www.wikidata.org/wiki/Special:EntityPage/Q586459" title="Structured data on this page hosted by Wikidata [g]" accesskey="g"><span>Wikidata item</span></a></li> </ul> </div> </div> </div> </div> </div> </div> </nav> </div> </div> </div> <div class="vector-column-end"> <div class="vector-sticky-pinned-container"> <nav class="vector-page-tools-landmark" aria-label="Page tools"> <div id="vector-page-tools-pinned-container" class="vector-pinned-container"> </div> </nav> <nav class="vector-appearance-landmark" aria-label="Appearance"> <div id="vector-appearance-pinned-container" class="vector-pinned-container"> <div id="vector-appearance" class="vector-appearance vector-pinnable-element"> <div class="vector-pinnable-header vector-appearance-pinnable-header vector-pinnable-header-pinned" data-feature-name="appearance-pinned" data-pinnable-element-id="vector-appearance" data-pinned-container-id="vector-appearance-pinned-container" data-unpinned-container-id="vector-appearance-unpinned-container" > <div class="vector-pinnable-header-label">Appearance</div> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-pin-button" data-event-name="pinnable-header.vector-appearance.pin">move to sidebar</button> <button class="vector-pinnable-header-toggle-button vector-pinnable-header-unpin-button" data-event-name="pinnable-header.vector-appearance.unpin">hide</button> </div> </div> </div> </nav> </div> </div> <div id="bodyContent" class="vector-body" aria-labelledby="firstHeading" data-mw-ve-target-container> <div class="vector-body-before-content"> <div class="mw-indicators"> </div> <div id="siteSub" class="noprint">From Wikipedia, the free encyclopedia</div> </div> <div id="contentSub"><div id="mw-content-subtitle"></div></div> <div id="mw-content-text" class="mw-body-content"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr"><div class="shortdescription nomobile noexcerpt noprint searchaux" style="display:none">Automatic detection of the type of an expression in a formal language</div> <style data-mw-deduplicate="TemplateStyles:r1129693374">.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}</style><style data-mw-deduplicate="TemplateStyles:r1246091330">.mw-parser-output .sidebar{width:22em;float:right;clear:right;margin:0.5em 0 1em 1em;background:var(--background-color-neutral-subtle,#f8f9fa);border:1px solid var(--border-color-base,#a2a9b1);padding:0.2em;text-align:center;line-height:1.4em;font-size:88%;border-collapse:collapse;display:table}body.skin-minerva .mw-parser-output .sidebar{display:table!important;float:right!important;margin:0.5em 0 1em 1em!important}.mw-parser-output .sidebar-subgroup{width:100%;margin:0;border-spacing:0}.mw-parser-output .sidebar-left{float:left;clear:left;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-none{float:none;clear:both;margin:0.5em 1em 1em 0}.mw-parser-output .sidebar-outer-title{padding:0 0.4em 0.2em;font-size:125%;line-height:1.2em;font-weight:bold}.mw-parser-output .sidebar-top-image{padding:0.4em}.mw-parser-output .sidebar-top-caption,.mw-parser-output .sidebar-pretitle-with-top-image,.mw-parser-output .sidebar-caption{padding:0.2em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-pretitle{padding:0.4em 0.4em 0;line-height:1.2em}.mw-parser-output .sidebar-title,.mw-parser-output .sidebar-title-with-pretitle{padding:0.2em 0.8em;font-size:145%;line-height:1.2em}.mw-parser-output .sidebar-title-with-pretitle{padding:0.1em 0.4em}.mw-parser-output .sidebar-image{padding:0.2em 0.4em 0.4em}.mw-parser-output .sidebar-heading{padding:0.1em 0.4em}.mw-parser-output .sidebar-content{padding:0 0.5em 0.4em}.mw-parser-output .sidebar-content-with-subgroup{padding:0.1em 0.4em 0.2em}.mw-parser-output .sidebar-above,.mw-parser-output .sidebar-below{padding:0.3em 0.8em;font-weight:bold}.mw-parser-output .sidebar-collapse .sidebar-above,.mw-parser-output .sidebar-collapse .sidebar-below{border-top:1px solid #aaa;border-bottom:1px solid #aaa}.mw-parser-output .sidebar-navbar{text-align:right;font-size:115%;padding:0 0.4em 0.4em}.mw-parser-output .sidebar-list-title{padding:0 0.4em;text-align:left;font-weight:bold;line-height:1.6em;font-size:105%}.mw-parser-output .sidebar-list-title-c{padding:0 0.4em;text-align:center;margin:0 3.3em}@media(max-width:640px){body.mediawiki .mw-parser-output .sidebar{width:100%!important;clear:both;float:none!important;margin-left:0!important;margin-right:0!important}}body.skin--responsive .mw-parser-output .sidebar a>img{max-width:none!important}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-night .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-list-title,html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle{background:transparent!important}html.skin-theme-clientpref-os .mw-parser-output .sidebar:not(.notheme) .sidebar-title-with-pretitle a{color:var(--color-progressive)!important}}@media print{body.ns-0 .mw-parser-output .sidebar{display:none!important}}</style><table class="sidebar nomobile nowraplinks" style="margin-top: 0.5em;"><tbody><tr><th class="sidebar-title"><a href="/wiki/Type_system" title="Type system">Type systems</a></th></tr><tr><th class="sidebar-heading"> General concepts</th></tr><tr><td class="sidebar-content" style="text-align: left;"> <ul><li><a href="/wiki/Type_safety" title="Type safety">Type safety</a></li> <li><a href="/wiki/Strong_and_weak_typing" title="Strong and weak typing">Strong vs. weak typing</a></li></ul></td> </tr><tr><th class="sidebar-heading"> Major categories</th></tr><tr><td class="sidebar-content" style="text-align: left;"> <ul><li><a href="/wiki/Type_system#Static_type_checking" title="Type system">Static</a> vs. <a href="/wiki/Type_system#Dynamic_type_checking_and_runtime_type_information" title="Type system">dynamic</a></li> <li><a href="/wiki/Manifest_typing" title="Manifest typing">Manifest</a> vs. <a class="mw-selflink selflink">inferred</a></li> <li><a href="/wiki/Nominal_type_system" title="Nominal type system">Nominal</a> vs. <a href="/wiki/Structural_type_system" title="Structural type system">structural</a></li> <li><a href="/wiki/Duck_typing" title="Duck typing">Duck typing</a></li></ul></td> </tr><tr><th class="sidebar-heading"> Minor categories</th></tr><tr><td class="sidebar-content" style="text-align: left;"> <ul><li><a href="/wiki/Abstract_type" title="Abstract type">Abstract</a></li> <li><a href="/wiki/Dependent_type" title="Dependent type">Dependent</a></li> <li><a href="/wiki/Flow-sensitive_typing" title="Flow-sensitive typing">Flow-sensitive</a></li> <li><a href="/wiki/Gradual_typing" title="Gradual typing">Gradual</a></li> <li><a href="/wiki/Intersection_type" title="Intersection type">Intersection</a></li> <li><a href="/wiki/Latent_typing" title="Latent typing">Latent</a></li> <li><a href="/wiki/Refinement_type" title="Refinement type">Refinement</a></li> <li><a href="/wiki/Substructural_type_system" title="Substructural type system">Substructural</a></li> <li><a href="/wiki/Uniqueness_type" title="Uniqueness type">Unique</a></li> <li><a href="/wiki/Session_type" title="Session type">Session</a></li></ul></td> </tr><tr><td class="sidebar-navbar"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1129693374" /><style data-mw-deduplicate="TemplateStyles:r1239400231">.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}</style><div class="navbar plainlinks hlist navbar-mini"><ul><li class="nv-view"><a href="/wiki/Template:Type_systems" title="Template:Type systems"><abbr title="View this template">v</abbr></a></li><li class="nv-talk"><a href="/wiki/Template_talk:Type_systems" title="Template talk:Type systems"><abbr title="Discuss this template">t</abbr></a></li><li class="nv-edit"><a href="/wiki/Special:EditPage/Template:Type_systems" title="Special:EditPage/Template:Type systems"><abbr title="Edit this template">e</abbr></a></li></ul></div></td></tr></tbody></table> <p><b>Type inference</b>, sometimes called <b>type reconstruction</b>,<sup id="cite_ref-TAPL_1-0" class="reference"><a href="#cite_note-TAPL-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup><sup class="reference nowrap"><span title="Pages: 320">&#58;&#8202;320&#8202;</span></sup> refers to the automatic detection of the <a href="/wiki/Type_(type_theory)" class="mw-redirect" title="Type (type theory)">type</a> of an expression in a <a href="/wiki/Formal_language" title="Formal language">formal language</a>. These include <a href="/wiki/Programming_language" title="Programming language">programming languages</a> and mathematical <a href="/wiki/Type_system" title="Type system">type systems</a>, but also <a href="/wiki/Natural_languages" class="mw-redirect" title="Natural languages">natural languages</a> in some branches of <a href="/wiki/Computer_science" title="Computer science">computer science</a> and <a href="/wiki/Linguistics" title="Linguistics">linguistics</a>. </p> <meta property="mw:PageProp/toc" /> <div class="mw-heading mw-heading2"><h2 id="Nontechnical_explanation">Nontechnical explanation</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=1" title="Edit section: Nontechnical explanation"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In a typed language, a term's type determines the ways it can and cannot be used in that language. For example, consider the English language and terms that could fill in the blank in the phrase "sing _." The term "a song" is of singable type, so it could be placed in the blank to form a meaningful phrase: "sing a song." On the other hand, the term "a friend" does not have the singable type, so "sing a friend" is nonsense. At best it might be metaphor; bending type rules is a feature of poetic language. </p><p>A term's type can also affect the interpretation of operations involving that term. For instance, "a song" is of composable type, so we interpret it as the thing created in the phrase "write a song". On the other hand, "a friend" is of recipient type, so we interpret it as the addressee in the phrase "write a friend". In normal language, we would be surprised if "write a song" meant addressing a letter to a song or "write a friend" meant drafting a friend on paper. </p><p>Terms with different types can even refer to materially the same thing. For example, we would interpret "to hang up the clothes line" as putting it into use, but "to hang up the leash" as putting it away, even though, in context, both "clothes line" and "leash" might refer the same rope, just at different times. </p><p>Typings are often used to prevent an object from being considered too generally. For instance, if the type system treats all numbers as the same, then a programmer who accidentally writes code where <code>4</code> is supposed to mean "4 seconds" but is interpreted as "4 meters" would have no warning of their mistake until it caused problems at runtime. By incorporating <a href="/wiki/Unit_of_measurement" title="Unit of measurement">units</a> into the type system, these mistakes can be detected much earlier. As another example, <a href="/wiki/Russell%27s_paradox" title="Russell&#39;s paradox">Russell's paradox</a> arises when anything can be a set element and any predicate can define a set, but more careful typing gives several ways to resolve the paradox. In fact, Russell's paradox sparked early versions of type theory. </p><p>There are several ways that a term can get its type: </p> <ul><li>The type might be provided from somewhere outside the passage. For instance, if a speaker refers to "a song" in English, they generally do not have to tell the listener that "a song" is singable and composable; that information is part of their shared background knowledge.</li> <li>The type can be declared explicitly. For example, a programmer might write a statement like <code>delay: seconds&#160;:= 4</code> in their code, where the colon is the conventional mathematical symbol to mark a term with its type. That is, this statement is not only setting <code>delay</code> to the value <code>4</code>, but the <code>delay: seconds</code> part also indicates that <code>delay</code>'s type is an amount of time in seconds.</li> <li>The type can be <b>inferred</b> from context. For example, in the phrase "I bought it for a song", we can observe that trying to give the term "a song" types like "singable" and "composable" would lead to nonsense, whereas the type "amount of currency" works out. Therefore, without having to be told, we conclude that "song" here must mean "little to nothing", as in the English idiom "<i lang="en"><a href="https://en.wiktionary.org/wiki/for_a_song#English" class="extiw" title="wikt:for a song">for a song</a></i>", not "a piece of music, usually with lyrics".</li></ul> <p>Especially in programming languages, there may not be much shared background knowledge available to the computer. In <a href="/wiki/Manifest_typing" title="Manifest typing">manifestly typed</a> languages, this means that most types have to be declared explicitly. <b>Type inference</b> aims to alleviate this burden, freeing the author from declaring types that the computer should be able to deduce from context. </p> <div class="mw-heading mw-heading2"><h2 id="Type-checking_vs._type-inference">Type-checking vs. type-inference</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=2" title="Edit section: Type-checking vs. type-inference"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>In a typing, an expression E is opposed to a type T, formally written as E&#160;: T. Usually a typing only makes sense within some context, which is omitted here. </p><p>In this setting, the following questions are of particular interest: </p> <ol><li>E&#160;: T? In this case, both an expression E and a type T are given. Now, is E really a T? This scenario is known as <a href="/wiki/Type-checking" class="mw-redirect" title="Type-checking">type-checking</a>.</li> <li>E&#160;: _? Here, only the expression is known. If there is a way to derive a type for E, then we have accomplished <i>type inference</i>.</li> <li>_&#160;: T? The other way round. Given only a type, is there any expression for it or does the type have no values? Is there any example of a T? This is known as <a href="/wiki/Type_inhabitation" title="Type inhabitation">type inhabitation</a>.</li></ol> <p>For the <a href="/wiki/Simply_typed_lambda_calculus" title="Simply typed lambda calculus">simply typed lambda calculus</a>, all three questions are <a href="/wiki/Decidability_(logic)#Decidability_of_a_theory" title="Decidability (logic)">decidable</a>. The situation is not as comfortable when more <a href="/wiki/Expressive_power_(computer_science)" title="Expressive power (computer science)">expressive</a> types are allowed. </p> <div class="mw-heading mw-heading2"><h2 id="Types_in_programming_languages">Types in programming languages</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=3" title="Edit section: Types in programming languages"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1251242444">.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}</style><table class="box-More_citations_needed_section plainlinks metadata ambox ambox-content ambox-Refimprove" role="presentation"><tbody><tr><td class="mbox-image"><div class="mbox-image-div"><span typeof="mw:File"><a href="/wiki/File:Question_book-new.svg" class="mw-file-description"><img alt="" src="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/50px-Question_book-new.svg.png" decoding="async" width="50" height="39" class="mw-file-element" srcset="//upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/75px-Question_book-new.svg.png 1.5x, //upload.wikimedia.org/wikipedia/en/thumb/9/99/Question_book-new.svg/100px-Question_book-new.svg.png 2x" data-file-width="512" data-file-height="399" /></a></span></div></td><td class="mbox-text"><div class="mbox-text-span">This section <b>needs additional citations for <a href="/wiki/Wikipedia:Verifiability" title="Wikipedia:Verifiability">verification</a></b>.<span class="hide-when-compact"> Please help <a href="/wiki/Special:EditPage/Type_inference" title="Special:EditPage/Type inference">improve this article</a> by <a href="/wiki/Help:Referencing_for_beginners" title="Help:Referencing for beginners">adding citations to reliable sources</a>&#32;in this section. Unsourced material may be challenged and removed.</span> <span class="date-container"><i>(<span class="date">November 2020</span>)</i></span><span class="hide-when-compact"><i> (<small><a href="/wiki/Help:Maintenance_template_removal" title="Help:Maintenance template removal">Learn how and when to remove this message</a></small>)</i></span></div></td></tr></tbody></table> <p>Types are a feature present in some <a href="/wiki/Strongly-typed_programming_language" class="mw-redirect" title="Strongly-typed programming language">strongly</a> <a href="/wiki/Type_system#Static_typing" title="Type system">statically typed</a> languages. It is often characteristic of <a href="/wiki/Functional_programming_language" class="mw-redirect" title="Functional programming language">functional programming languages</a> in general. Some languages that include type inference include <a href="/wiki/C23_(C_standard_revision)" title="C23 (C standard revision)">C23</a>,<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">&#91;</span>2<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/C%2B%2B11" title="C++11">C++11</a>,<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">&#91;</span>3<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/C_Sharp_3.0#Local_variable_type_inference" title="C Sharp 3.0">C#</a> (starting with version 3.0), <a href="/wiki/Chapel_(programming_language)" title="Chapel (programming language)">Chapel</a>, <a href="/wiki/Clean_(programming_language)" title="Clean (programming language)">Clean</a>, <a href="/wiki/Crystal_(programming_language)" title="Crystal (programming language)">Crystal</a>, <a href="/wiki/D_(programming_language)" title="D (programming language)">D</a>, <a href="/wiki/F_Sharp_(programming_language)" title="F Sharp (programming language)">F#</a>,<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">&#91;</span>4<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/FreeBASIC" title="FreeBASIC">FreeBASIC</a>, <a href="/wiki/Go_(programming_language)" title="Go (programming language)">Go</a>, <a href="/wiki/Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a>, <a href="/wiki/Java_(programming_language)" title="Java (programming language)">Java</a> (starting with version 10), <a href="/wiki/Julia_(programming_language)" title="Julia (programming language)">Julia</a>,<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">&#91;</span>5<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/Kotlin_(programming_language)" title="Kotlin (programming language)">Kotlin</a>,<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">&#91;</span>6<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/ML_(programming_language)" title="ML (programming language)">ML</a>, <a href="/wiki/Nim_(programming_language)" title="Nim (programming language)">Nim</a>, <a href="/wiki/OCaml" title="OCaml">OCaml</a>, <a href="/wiki/Opa_(programming_language)" title="Opa (programming language)">Opa</a>, Q#, <a href="/wiki/RPython" class="mw-redirect" title="RPython">RPython</a>, <a href="/wiki/Rust_(programming_language)" title="Rust (programming language)">Rust</a>,<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">&#91;</span>7<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/Scala_(programming_language)" title="Scala (programming language)">Scala</a>,<sup id="cite_ref-8" class="reference"><a href="#cite_note-8"><span class="cite-bracket">&#91;</span>8<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/Swift_(programming_language)" title="Swift (programming language)">Swift</a>,<sup id="cite_ref-9" class="reference"><a href="#cite_note-9"><span class="cite-bracket">&#91;</span>9<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/TypeScript" title="TypeScript">TypeScript</a>,<sup id="cite_ref-10" class="reference"><a href="#cite_note-10"><span class="cite-bracket">&#91;</span>10<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/Vala_(programming_language)" title="Vala (programming language)">Vala</a>,<sup id="cite_ref-11" class="reference"><a href="#cite_note-11"><span class="cite-bracket">&#91;</span>11<span class="cite-bracket">&#93;</span></a></sup> <a href="/wiki/Dart_(programming_language)" title="Dart (programming language)">Dart</a>,<sup id="cite_ref-12" class="reference"><a href="#cite_note-12"><span class="cite-bracket">&#91;</span>12<span class="cite-bracket">&#93;</span></a></sup> and <a href="/wiki/Visual_Basic_.NET#2008_(VB_9.0)" class="mw-redirect" title="Visual Basic .NET">Visual Basic</a><sup id="cite_ref-13" class="reference"><a href="#cite_note-13"><span class="cite-bracket">&#91;</span>13<span class="cite-bracket">&#93;</span></a></sup> (starting with version 9.0). The majority of them use a simple form of type inference; the <a href="/wiki/Hindley%E2%80%93Milner_type_system" title="Hindley–Milner type system">Hindley–Milner type system</a> can provide more complete type inference. The ability to infer types automatically makes many programming tasks easier, leaving the programmer free to omit <a href="/wiki/Type_signature" title="Type signature">type annotations</a> while still permitting type checking. </p><p>In some programming languages, all values have a <a href="/wiki/Data_type" title="Data type">data type</a> explicitly declared at <a href="/wiki/Compile_time" title="Compile time">compile time</a>, limiting the values a particular expression can take on at <a href="/wiki/Run_time_(program_lifecycle_phase)" class="mw-redirect" title="Run time (program lifecycle phase)">run-time</a>. Increasingly, <a href="/wiki/Just-in-time_compilation" title="Just-in-time compilation">just-in-time compilation</a> blurs the distinction between run time and compile time. However, historically, if the type of a value is known only at run-time, these languages are <a href="/wiki/Dynamically_typed" class="mw-redirect" title="Dynamically typed">dynamically typed</a>. In other languages, the type of an expression is known only at <a href="/wiki/Compile_time" title="Compile time">compile time</a>; these languages are <a href="/wiki/Statically_typed" class="mw-redirect" title="Statically typed">statically typed</a>. In most statically typed languages, the input and output types of functions and <a href="/wiki/Local_variable" title="Local variable">local variables</a> ordinarily must be explicitly provided by type annotations. For example, in <a href="/wiki/ANSI_C" title="ANSI C">ANSI C</a>: </p> <div class="mw-highlight mw-highlight-lang-c mw-content-ltr" dir="ltr"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="nf">add_one</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">result</span><span class="p">;</span><span class="w"> </span><span class="cm">/* declare integer result */</span> <span class="w"> </span><span class="n">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">result</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>The <a href="/wiki/Type_signature" title="Type signature">signature</a> of this function definition, <code>int add_one(int x)</code>, declares that <code>add_one</code> is a function that takes one argument, an <a href="/wiki/Integer_(computer_science)" title="Integer (computer science)">integer</a>, and returns an integer. <code>int result;</code> declares that the local variable <code>result</code> is an integer. In a hypothetical language supporting type inference, the code might be written like this instead: </p> <div class="mw-highlight mw-highlight-lang-javascript mw-content-ltr" dir="ltr"><pre><span></span><span class="nx">add_one</span><span class="p">(</span><span class="nx">x</span><span class="p">)</span><span class="w"> </span><span class="p">{</span> <span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">result</span><span class="p">;</span><span class="w"> </span><span class="cm">/* inferred-type variable result */</span> <span class="w"> </span><span class="kd">var</span><span class="w"> </span><span class="nx">result2</span><span class="p">;</span><span class="w"> </span><span class="cm">/* inferred-type variable result #2 */</span> <span class="w"> </span><span class="nx">result</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mf">1</span><span class="p">;</span> <span class="w"> </span><span class="nx">result2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nx">x</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mf">1.0</span><span class="p">;</span><span class="w"> </span><span class="cm">/* this line won&#39;t work (in the proposed language) */</span> <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="nx">result</span><span class="p">;</span> <span class="p">}</span> </pre></div> <p>This is identical to how code is written in the language <a href="/wiki/Dart_(programming_language)" title="Dart (programming language)">Dart</a>, except that it is subject to some added constraints as described below. It would be possible to <i>infer</i> the types of all the variables at compile time. In the example above, the compiler would infer that <code>result</code> and <code>x</code> have type integer since the constant <code>1</code> is type integer, and hence that <code>add_one</code> is a function <code>int -&gt; int</code>. The variable <code>result2</code> isn't used in a legal manner, so it wouldn't have a type. </p><p>In the imaginary language in which the last example is written, the compiler would assume that, in the absence of information to the contrary, <code>+</code> takes two integers and returns one integer. (This is how it works in, for example, <a href="/wiki/OCaml" title="OCaml">OCaml</a>.) From this, the type inferencer can infer that the type of <code>x + 1</code> is an integer, which means <code>result</code> is an integer and thus the return value of <code>add_one</code> is an integer. Similarly, since <code>+</code> requires both of its arguments be of the same type, <code>x</code> must be an integer, and thus, <code>add_one</code> accepts one integer as an argument. </p><p>However, in the subsequent line, <i>result2</i> is calculated by adding a decimal <code>1.0</code> with <a href="/wiki/Floating-point_arithmetic" title="Floating-point arithmetic">floating-point arithmetic</a>, causing a conflict in the use of <code>x</code> for both integer and floating-point expressions. The correct type-inference algorithm for such a situation has been known <a href="#Hindley–Milner_type_inference_algorithm">since 1958</a> and has been known to be correct since 1982. It revisits the prior inferences and uses the most general type from the outset: in this case floating-point. This can however have detrimental implications, for instance using a floating-point from the outset can introduce precision issues that would have not been there with an integer type. </p><p>Frequently, however, degenerate type-inference algorithms are used that cannot backtrack and instead generate an error message in such a situation. This behavior may be preferable as type inference may not always be neutral algorithmically, as illustrated by the prior floating-point precision issue. </p><p>An algorithm of intermediate generality implicitly declares <i>result2</i> as a floating-point variable, and the addition implicitly converts <code>x</code> to a floating point. This can be correct if the calling contexts never supply a floating point argument. Such a situation shows the difference between <i>type inference</i>, which does not involve <a href="/wiki/Type_conversion" title="Type conversion">type conversion</a>, and <a href="/wiki/Implicit_type_conversion" class="mw-redirect" title="Implicit type conversion">implicit type conversion</a>, which forces data to a different data type, often without restrictions. </p><p>Finally, a significant downside of complex type-inference algorithm is that the resulting type inference resolution is not going to be obvious to humans (notably because of the backtracking), which can be detrimental as code is primarily intended to be comprehensible to humans. </p><p>The recent emergence of <a href="/wiki/Just-in-time_compilation" title="Just-in-time compilation">just-in-time compilation</a> allows for hybrid approaches where the type of arguments supplied by the various calling context is known at compile time, and can generate a large number of compiled versions of the same function. Each compiled version can then be optimized for a different set of types. For instance, JIT compilation allows there to be at least two compiled versions of <i>add_one</i>: </p> <dl><dd>A version that accepts an integer input and uses implicit type conversion.</dd> <dd>A version that accepts a floating-point number as input and uses floating point instructions throughout.</dd></dl> <div class="mw-heading mw-heading2"><h2 id="Technical_description">Technical description</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=4" title="Edit section: Technical description"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Type inference is the ability to automatically deduce, either partially or fully, the type of an expression at compile time. The compiler is often able to infer the type of a variable or the <a href="/wiki/Type_signature" title="Type signature">type signature</a> of a function, without explicit type annotations having been given. In many cases, it is possible to omit type annotations from a program completely if the type inference system is robust enough, or the program or language is simple enough. </p><p>To obtain the information required to infer the type of an expression, the compiler either gathers this information as an aggregate and subsequent reduction of the type annotations given for its subexpressions, or through an implicit understanding of the type of various atomic values (e.g. true&#160;: Bool; 42&#160;: Integer; 3.14159&#160;: Real; etc.). It is through recognition of the eventual reduction of expressions to implicitly typed atomic values that the compiler for a type inferring language is able to compile a program completely without type annotations. </p><p>In complex forms of <a href="/wiki/Higher-order_programming" title="Higher-order programming">higher-order programming</a> and <a href="/wiki/Polymorphism_(computer_science)" title="Polymorphism (computer science)">polymorphism</a>, it is not always possible for the compiler to infer as much, and type annotations are occasionally necessary for disambiguation. For instance, type inference with <a href="/wiki/Polymorphic_recursion" title="Polymorphic recursion">polymorphic recursion</a> is known to be undecidable. Furthermore, explicit type annotations can be used to optimize code by forcing the compiler to use a more specific (faster/smaller) type than it had inferred.<sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">&#91;</span>14<span class="cite-bracket">&#93;</span></a></sup> </p><p>Some methods for type inference are based on <a href="/wiki/Constraint_satisfaction_problem" title="Constraint satisfaction problem">constraint satisfaction</a><sup id="cite_ref-15" class="reference"><a href="#cite_note-15"><span class="cite-bracket">&#91;</span>15<span class="cite-bracket">&#93;</span></a></sup> or <a href="/wiki/Satisfiability_modulo_theories" title="Satisfiability modulo theories">satisfiability modulo theories</a>.<sup id="cite_ref-16" class="reference"><a href="#cite_note-16"><span class="cite-bracket">&#91;</span>16<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="High-Level_Example">High-Level Example</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=5" title="Edit section: High-Level Example"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>As an example, the <a href="/wiki/Haskell_(programming_language)" class="mw-redirect" title="Haskell (programming language)">Haskell</a> function <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code> applies a function to each element of a list, and may be defined as: </p> <div class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span></span><span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="kt">[]</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kt">[]</span> <span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="p">(</span><span class="n">first</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">first</span><span class="w"> </span><span class="kt">:</span><span class="w"> </span><span class="n">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">rest</span> </pre></div> <p>(Recall that <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="kt">:</span></code> in Haskell denotes <a href="/wiki/Cons" title="Cons">cons</a>, structuring a head element and a list tail into a bigger list or destructuring a nonempty list into its head element and its tail. It does not denote "of type" as in mathematics and elsewhere in this article; in Haskell that "of type" operator is written <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="ow">::</span></code> instead.) </p><p>Type inference on the <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code> function proceeds as follows. <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code> is a function of two arguments, so its type is constrained to be of the form <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">a</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">c</span></code>. In Haskell, the patterns <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="kt">[]</span></code> and <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="p">(</span><span class="n">first</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span></code> always match lists, so the second argument must be a list type: <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">b</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="p">[</span><span class="n">d</span><span class="p">]</span></code> for some type <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">d</span></code>. Its first argument <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span></code> is <a href="/wiki/Function_application" title="Function application">applied</a> to the argument <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">first</span></code>, which must have type <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">d</span></code>, corresponding with the type in the list argument, so <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="n">d</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">e</span></code> (<code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="ow">::</span></code> means "is of type") for some type <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">e</span></code>. The return value of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span><span class="w"> </span><span class="n">f</span></code>, finally, is a list of whatever <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span></code> produces, so <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="p">[</span><span class="n">e</span><span class="p">]</span></code>. </p><p>Putting the parts together leads to <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="p">(</span><span class="n">d</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">[</span><span class="n">d</span><span class="p">]</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">[</span><span class="n">e</span><span class="p">]</span></code>. Nothing is special about the type variables, so it can be relabeled as </p> <div style="" class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span></span><span class="nf">map</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">[</span><span class="n">b</span><span class="p">]</span> </pre></div> <p>It turns out that this is also the most general type, since no further constraints apply. As the inferred type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code> is <a href="/wiki/Parametric_polymorphism" title="Parametric polymorphism">parametrically polymorphic</a>, the type of the arguments and results of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span></code> are not inferred, but left as type variables, and so <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code> can be applied to functions and lists of various types, as long as the actual types match in each invocation. </p> <div class="mw-heading mw-heading2"><h2 id="Detailed_Example">Detailed Example</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=6" title="Edit section: Detailed Example"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>The algorithms used by programs like compilers are equivalent to the informally structured reasoning above, but a bit more verbose and methodical. The exact details depend on the inference algorithm chosen (see the following section for the best-known algorithm), but the example below gives the general idea. We again begin with the definition of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code>: </p> <div class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><pre><span></span><span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="kt">[]</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="kt">[]</span> <span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="p">(</span><span class="n">first</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span><span class="w"> </span><span class="ow">=</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">first</span><span class="w"> </span><span class="kt">:</span><span class="w"> </span><span class="n">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">rest</span> </pre></div> <p>(Again, remember that the <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="kt">:</span></code> here is the Haskell list constructor, not the "of type" operator, which Haskell instead spells <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="ow">::</span></code>.) </p><p>First, we make fresh type variables for each individual term: </p> <ul><li><code>α</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code> that we want to infer.</li> <li><code>β</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span></code> in the first equation.</li> <li><code>[γ]</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="kt">[]</span></code> on the left side of the first equation.</li> <li><code>[δ]</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="kt">[]</span></code> on the right side of the first equation.</li> <li><code>ε</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span></code> in the second equation.</li> <li><code>ζ -&gt; [ζ] -&gt; [ζ]</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="kt">:</span></code> on the left side of the first equation. (This pattern is known from its definition.)</li> <li><code>η</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">first</span></code>.</li> <li><code>θ</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">rest</span></code>.</li> <li><code>ι -&gt; [ι] -&gt; [ι]</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="kt">:</span></code> on the right side of the first equation.</li></ul> <p>Then we make fresh type variables for subexpressions built from these terms, constraining the type of the function being invoked accordingly: </p> <ul><li><code>κ</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="kt">[]</span></code>. We conclude that <code>α ~ β -&gt; [γ] -&gt; κ</code> where the "similar" symbol <code>~</code> means "unifies with"; we are saying that <code>α</code>, the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span></code>, must be compatible with the type of a function taking a <code>β</code> and a list of <code>γ</code>s and returning a <code>κ</code>.</li> <li><code>λ</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="p">(</span><span class="n">first</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span></code>. We conclude that <code>ζ -&gt; [ζ] -&gt; [ζ] ~ η -&gt; θ -&gt; λ</code>.</li> <li><code>μ</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="p">(</span><span class="n">first</span><span class="kt">:</span><span class="n">rest</span><span class="p">)</span></code>. We conclude that <code>α ~ ε -&gt; λ -&gt; μ</code>.</li> <li><code>ν</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span><span class="w"> </span><span class="n">first</span></code>. We conclude that <code>ε ~ η -&gt; ν</code>.</li> <li><code>ξ</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">rest</span></code>. We conclude that <code>α ~ ε -&gt; θ -&gt; ξ</code>.</li> <li><code>ο</code> shall denote the type of <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">f</span><span class="w"> </span><span class="n">first</span><span class="w"> </span><span class="kt">:</span><span class="w"> </span><span class="n">map</span><span class="w"> </span><span class="n">f</span><span class="w"> </span><span class="n">rest</span></code>. We conclude that <code>ι -&gt; [ι] -&gt; [ι] ~ ν -&gt; ξ -&gt; ο</code>.</li></ul> <p>We also constrain the left and right sides of each equation to unify with each other: <code>κ ~ [δ]</code> and <code>μ ~ ο</code>. Altogether the system of unifications to solve is: </p> <pre>α ~ β -&gt; [γ] -&gt; κ ζ -&gt; [ζ] -&gt; [ζ] ~ η -&gt; θ -&gt; λ α ~ ε -&gt; λ -&gt; μ ε ~ η -&gt; ν α ~ ε -&gt; θ -&gt; ξ ι -&gt; [ι] -&gt; [ι] ~ ν -&gt; ξ -&gt; ο κ ~ [δ] μ ~ ο </pre> <p>Then we substitute until no further variables can be eliminated. The exact order is immaterial; if the code type-checks, any order will lead to the same final form. Let us begin by substituting <code>ο</code> for <code>μ</code> and <code>[δ]</code> for <code>κ</code>: </p> <pre>α ~ β -&gt; [γ] -&gt; [δ] ζ -&gt; [ζ] -&gt; [ζ] ~ η -&gt; θ -&gt; λ α ~ ε -&gt; λ -&gt; ο ε ~ η -&gt; ν α ~ ε -&gt; θ -&gt; ξ ι -&gt; [ι] -&gt; [ι] ~ ν -&gt; ξ -&gt; ο </pre> <p>Substituting <code>ζ</code> for <code>η</code>, <code>[ζ]</code> for <code>θ</code> and <code>λ</code>, <code>ι</code> for <code>ν</code>, and <code>[ι]</code> for <code>ξ</code> and <code>ο</code>, all possible because a type constructor like <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="err">·</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="err">·</span></code> is <a href="/wiki/Inverse_function#Definitions" title="Inverse function">invertible</a> in its arguments: </p> <pre>α ~ β -&gt; [γ] -&gt; [δ] α ~ ε -&gt; [ζ] -&gt; [ι] ε ~ ζ -&gt; ι </pre> <p>Substituting <code>ζ -&gt; ι</code> for <code>ε</code> and <code>β -&gt; [γ] -&gt; [δ]</code> for <code>α</code>, keeping the second constraint around so that we can recover <code>α</code> at the end: </p> <pre>α ~ (ζ -&gt; ι) -&gt; [ζ] -&gt; [ι] β -&gt; [γ] -&gt; [δ] ~ (ζ -&gt; ι) -&gt; [ζ] -&gt; [ι] </pre> <p>And, finally, substituting <code>(ζ -&gt; ι)</code> for <code>β</code> as well as <code>ζ</code> for <code>γ</code> and <code>ι</code> for <code>δ</code> because a type constructor like <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="p">[</span><span class="err">·</span><span class="p">]</span></code> is <a href="/wiki/Inverse_function#Definitions" title="Inverse function">invertible</a> eliminates all the variables specific to the second constraint: </p> <pre>α ~ (ζ -&gt; ι) -&gt; [ζ] -&gt; [ι] </pre> <p>No more substitutions are possible, and relabeling gives us <code class="mw-highlight mw-highlight-lang-haskell mw-content-ltr" dir="ltr"><span class="nf">map</span><span class="w"> </span><span class="ow">::</span><span class="w"> </span><span class="p">(</span><span class="n">a</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="n">b</span><span class="p">)</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">[</span><span class="n">a</span><span class="p">]</span><span class="w"> </span><span class="ow">-&gt;</span><span class="w"> </span><span class="p">[</span><span class="n">b</span><span class="p">]</span></code>, the same as we found without going into these details. </p> <div class="mw-heading mw-heading2"><h2 id="Hindley–Milner_type_inference_algorithm"><span id="Hindley.E2.80.93Milner_type_inference_algorithm"></span><span class="anchor" id="algorithm"></span>Hindley–Milner type inference algorithm</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=7" title="Edit section: Hindley–Milner type inference algorithm"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1236090951">.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}</style><div role="note" class="hatnote navigation-not-searchable">Main article: <a href="/wiki/Hindley%E2%80%93Milner_type_system" title="Hindley–Milner type system">Hindley–Milner type system</a></div> <p>The algorithm first used to perform type inference is now informally termed the Hindley–Milner algorithm, although the algorithm should properly be attributed to Damas and Milner.<sup id="cite_ref-Damas-and-Milner-1982_17-0" class="reference"><a href="#cite_note-Damas-and-Milner-1982-17"><span class="cite-bracket">&#91;</span>17<span class="cite-bracket">&#93;</span></a></sup> It is also traditionally called <i>type reconstruction</i>.<sup id="cite_ref-TAPL_1-1" class="reference"><a href="#cite_note-TAPL-1"><span class="cite-bracket">&#91;</span>1<span class="cite-bracket">&#93;</span></a></sup><sup class="reference nowrap"><span title="Pages: 320">&#58;&#8202;320&#8202;</span></sup> If a term is well-typed in accordance with Hindley–Milner typing rules, then the rules generate a principal typing for the term. The process of discovering this principal typing is the process of "reconstruction". </p><p>The origin of this algorithm is the type inference algorithm for the <a href="/wiki/Simply_typed_lambda_calculus" title="Simply typed lambda calculus">simply typed lambda calculus</a> that was devised by <a href="/wiki/Haskell_Curry" title="Haskell Curry">Haskell Curry</a> and <a href="/wiki/Robert_Feys" title="Robert Feys">Robert Feys</a> in 1958.<sup class="noprint Inline-Template Template-Fact" style="white-space:nowrap;">&#91;<i><a href="/wiki/Wikipedia:Citation_needed" title="Wikipedia:Citation needed"><span title="This probably refers to &#91;Combinatory Logic Volume 1 https&#58;//www.worldcat.org/title/combinatory-logic-vol-1-haskell-b-curry-and-robert-feys-with-two-sections-by-william-craig/oclc/769219250&#93;, however this actual claim is hard to find - it&#39;s 417 pages and has no table of contents. Please add a citation with page numbers if you can confirm this is a valid source. Also update Hindley–Milner type system as this claim is present there too. (February 2021)">citation needed</span></a></i>&#93;</sup> In 1969 <a href="/wiki/J._Roger_Hindley" title="J. Roger Hindley">J. Roger Hindley</a> extended this work and proved that their algorithm always inferred the most general type. In 1978 <a href="/wiki/Robin_Milner" title="Robin Milner">Robin Milner</a>,<sup id="cite_ref-18" class="reference"><a href="#cite_note-18"><span class="cite-bracket">&#91;</span>18<span class="cite-bracket">&#93;</span></a></sup> independently of Hindley's work, provided an equivalent algorithm, <a href="/wiki/Algorithm_W" class="mw-redirect" title="Algorithm W">Algorithm W</a>. In 1982 <a href="/w/index.php?title=Luis_Damas&amp;action=edit&amp;redlink=1" class="new" title="Luis Damas (page does not exist)">Luis Damas</a><sup id="cite_ref-Damas-and-Milner-1982_17-1" class="reference"><a href="#cite_note-Damas-and-Milner-1982-17"><span class="cite-bracket">&#91;</span>17<span class="cite-bracket">&#93;</span></a></sup> finally proved that Milner's algorithm is complete and extended it to support systems with polymorphic references. </p> <div class="mw-heading mw-heading2"><h2 id="Side-effects_of_using_the_most_general_type">Side-effects of using the most general type</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=8" title="Edit section: Side-effects of using the most general type"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>By design, type inference will infer the most general type appropriate. However, many languages, especially older programming languages, have slightly unsound type systems, where using a more general types may not always be algorithmically neutral. Typical cases include: </p> <ul><li>Floating-point types being considered as generalizations of integer types. Actually, floating-point arithmetic has different precision and wrapping issues than integers do.</li> <li>Variant/dynamic types being considered as generalizations of other types in cases where this affects the selection of operator overloads. For example, the <code>+</code> operator may add integers but may concatenate variants as strings, even if those variants hold integers.</li></ul> <div class="mw-heading mw-heading2"><h2 id="Type_inference_for_natural_languages">Type inference for natural languages</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=9" title="Edit section: Type inference for natural languages"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <p>Type inference algorithms have been used to analyze <a href="/wiki/Natural_languages" class="mw-redirect" title="Natural languages">natural languages</a> as well as programming languages.<sup id="cite_ref-19" class="reference"><a href="#cite_note-19"><span class="cite-bracket">&#91;</span>19<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-20" class="reference"><a href="#cite_note-20"><span class="cite-bracket">&#91;</span>20<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-21" class="reference"><a href="#cite_note-21"><span class="cite-bracket">&#91;</span>21<span class="cite-bracket">&#93;</span></a></sup> Type inference algorithms are also used in some <a href="/wiki/Grammar_induction" title="Grammar induction">grammar induction</a><sup id="cite_ref-22" class="reference"><a href="#cite_note-22"><span class="cite-bracket">&#91;</span>22<span class="cite-bracket">&#93;</span></a></sup><sup id="cite_ref-23" class="reference"><a href="#cite_note-23"><span class="cite-bracket">&#91;</span>23<span class="cite-bracket">&#93;</span></a></sup> and <a href="/wiki/Constraint-based_grammar" class="mw-redirect" title="Constraint-based grammar">constraint-based grammar</a> systems for natural languages.<sup id="cite_ref-Shieber1992_24-0" class="reference"><a href="#cite_note-Shieber1992-24"><span class="cite-bracket">&#91;</span>24<span class="cite-bracket">&#93;</span></a></sup> </p> <div class="mw-heading mw-heading2"><h2 id="References">References</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=10" title="Edit section: References"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <style data-mw-deduplicate="TemplateStyles:r1239543626">.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}</style><div class="reflist"> <div class="mw-references-wrap mw-references-columns"><ol class="references"> <li id="cite_note-TAPL-1"><span class="mw-cite-backlink">^ <a href="#cite_ref-TAPL_1-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-TAPL_1-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("//upload.wikimedia.org/wikipedia/commons/6/65/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("//upload.wikimedia.org/wikipedia/commons/d/d6/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("//upload.wikimedia.org/wikipedia/commons/a/aa/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("//upload.wikimedia.org/wikipedia/commons/4/4c/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}</style><cite id="CITEREFBenjamin_C._Pierce2002" class="citation book cs1"><a href="/wiki/Benjamin_C._Pierce" title="Benjamin C. Pierce">Benjamin C. Pierce</a> (2002). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=ti6zoAC9Ph8C"><i>Types and Programming Languages</i></a>. MIT Press. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-262-16209-8" title="Special:BookSources/978-0-262-16209-8"><bdi>978-0-262-16209-8</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Types+and+Programming+Languages&amp;rft.pub=MIT+Press&amp;rft.date=2002&amp;rft.isbn=978-0-262-16209-8&amp;rft.au=Benjamin+C.+Pierce&amp;rft_id=https%3A%2F%2Fbooks.google.com%2Fbooks%3Fid%3Dti6zoAC9Ph8C&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3007.htm">"WG14-N3007&#160;: Type inference for object definitions"</a>. <i>open-std.org</i>. 2022-06-10. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20221224105654/https://open-std.org/JTC1/SC22/WG14/www/docs/n3007.htm">Archived</a> from the original on December 24, 2022.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=open-std.org&amp;rft.atitle=WG14-N3007+%3A+Type+inference+for+object+definitions&amp;rft.date=2022-06-10&amp;rft_id=https%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg14%2Fwww%2Fdocs%2Fn3007.htm&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://en.cppreference.com/w/cpp/language/auto">"Placeholder type specifiers (since C++11) - cppreference.com"</a>. <i>en.cppreference.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-08-15</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=en.cppreference.com&amp;rft.atitle=Placeholder+type+specifiers+%28since+C%2B%2B11%29+-+cppreference.com&amp;rft_id=https%3A%2F%2Fen.cppreference.com%2Fw%2Fcpp%2Flanguage%2Fauto&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFcartermp" class="citation web cs1">cartermp. <a rel="nofollow" class="external text" href="https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/type-inference">"Type Inference - F#"</a>. <i>docs.microsoft.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-11-21</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=docs.microsoft.com&amp;rft.atitle=Type+Inference+-+F%23&amp;rft.au=cartermp&amp;rft_id=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Ffsharp%2Flanguage-reference%2Ftype-inference&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.julialang.org/en/v1/devdocs/inference/">"Inference · The Julia Language"</a>. <i>docs.julialang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-11-21</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=docs.julialang.org&amp;rft.atitle=Inference+%C2%B7+The+Julia+Language&amp;rft_id=https%3A%2F%2Fdocs.julialang.org%2Fen%2Fv1%2Fdevdocs%2Finference%2F&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://kotlinlang.org/spec/type-inference.html">"Kotlin language specification"</a>. <i>kotlinlang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-06-28</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=kotlinlang.org&amp;rft.atitle=Kotlin+language+specification&amp;rft_id=https%3A%2F%2Fkotlinlang.org%2Fspec%2Ftype-inference.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://doc.rust-lang.org/reference/statements.html?highlight=inference#let-statements">"Statements - The Rust Reference"</a>. <i>doc.rust-lang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-06-28</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=doc.rust-lang.org&amp;rft.atitle=Statements+-+The+Rust+Reference&amp;rft_id=https%3A%2F%2Fdoc.rust-lang.org%2Freference%2Fstatements.html%3Fhighlight%3Dinference%23let-statements&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-8">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.scala-lang.org/tour/type-inference.html">"Type Inference"</a>. <i>Scala Documentation</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-11-21</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=Scala+Documentation&amp;rft.atitle=Type+Inference&amp;rft_id=https%3A%2F%2Fdocs.scala-lang.org%2Ftour%2Ftype-inference.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-9">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html#ID322">"The Basics — The Swift Programming Language (Swift 5.5)"</a>. <i>docs.swift.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-06-28</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=docs.swift.org&amp;rft.atitle=The+Basics+%E2%80%94+The+Swift+Programming+Language+%28Swift+5.5%29&amp;rft_id=https%3A%2F%2Fdocs.swift.org%2Fswift-book%2FLanguageGuide%2FTheBasics.html%23ID322&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-10">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.typescriptlang.org/docs/handbook/type-inference.html">"Documentation - Type Inference"</a>. <i>www.typescriptlang.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-11-21</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=www.typescriptlang.org&amp;rft.atitle=Documentation+-+Type+Inference&amp;rft_id=https%3A%2F%2Fwww.typescriptlang.org%2Fdocs%2Fhandbook%2Ftype-inference.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-11">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://wiki.gnome.org/Projects/Vala/Tutorial#Type_Inference">"Projects/Vala/Tutorial - GNOME Wiki!"</a>. <i>wiki.gnome.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-06-28</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=wiki.gnome.org&amp;rft.atitle=Projects%2FVala%2FTutorial+-+GNOME+Wiki%21&amp;rft_id=https%3A%2F%2Fwiki.gnome.org%2FProjects%2FVala%2FTutorial%23Type_Inference&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-12">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://dart.dev/guides/language/type-system">"The Dart type system"</a>. <i>dart.dev</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-11-21</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=dart.dev&amp;rft.atitle=The+Dart+type+system&amp;rft_id=https%3A%2F%2Fdart.dev%2Fguides%2Flanguage%2Ftype-system&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-13">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFKathleenDollard" class="citation web cs1">KathleenDollard. <a rel="nofollow" class="external text" href="https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/variables/local-type-inference">"Local Type Inference - Visual Basic"</a>. <i>docs.microsoft.com</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2021-06-28</span></span>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=unknown&amp;rft.jtitle=docs.microsoft.com&amp;rft.atitle=Local+Type+Inference+-+Visual+Basic&amp;rft.au=KathleenDollard&amp;rft_id=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fvisual-basic%2Fprogramming-guide%2Flanguage-features%2Fvariables%2Flocal-type-inference&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFBryan_O&#39;SullivanDon_StewartJohn_Goerzen2008" class="citation book cs1">Bryan O'Sullivan; Don Stewart; John Goerzen (2008). <a rel="nofollow" class="external text" href="http://book.realworldhaskell.org/read/profiling-and-optimization.html">"Chapter 25. Profiling and optimization"</a>. <i>Real World Haskell</i>. O'Reilly.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=bookitem&amp;rft.atitle=Chapter+25.+Profiling+and+optimization&amp;rft.btitle=Real+World+Haskell&amp;rft.pub=O%27Reilly&amp;rft.date=2008&amp;rft.au=Bryan+O%27Sullivan&amp;rft.au=Don+Stewart&amp;rft.au=John+Goerzen&amp;rft_id=http%3A%2F%2Fbook.realworldhaskell.org%2Fread%2Fprofiling-and-optimization.html&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-15">^</a></b></span> <span class="reference-text">Talpin, Jean-Pierre, and Pierre Jouvelot. "<a rel="nofollow" class="external text" href="https://pdfs.semanticscholar.org/57b0/e240c36a26c05b2eb7b6ccf3fabbfd383b25.pdf">Polymorphic type, region and effect inference</a>." Journal of functional programming 2.3 (1992): 245-271.</span> </li> <li id="cite_note-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-16">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFHassanUrbanEilersMüller2018" class="citation book cs1">Hassan, Mostafa; Urban, Caterina; Eilers, Marco; Müller, Peter (2018). <a rel="nofollow" class="external text" href="https://link.springer.com/chapter/10.1007/978-3-319-96142-2_2">"MaxSMT-Based Type Inference for Python 3"</a>. <i>Computer Aided Verification</i>. Lecture Notes in Computer Science. Vol.&#160;10982. pp.&#160;<span class="nowrap">12–</span>19. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2F978-3-319-96142-2_2">10.1007/978-3-319-96142-2_2</a>. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-3-319-96141-5" title="Special:BookSources/978-3-319-96141-5"><bdi>978-3-319-96141-5</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=bookitem&amp;rft.atitle=MaxSMT-Based+Type+Inference+for+Python+3&amp;rft.btitle=Computer+Aided+Verification&amp;rft.series=Lecture+Notes+in+Computer+Science&amp;rft.pages=%3Cspan+class%3D%22nowrap%22%3E12-%3C%2Fspan%3E19&amp;rft.date=2018&amp;rft_id=info%3Adoi%2F10.1007%2F978-3-319-96142-2_2&amp;rft.isbn=978-3-319-96141-5&amp;rft.aulast=Hassan&amp;rft.aufirst=Mostafa&amp;rft.au=Urban%2C+Caterina&amp;rft.au=Eilers%2C+Marco&amp;rft.au=M%C3%BCller%2C+Peter&amp;rft_id=https%3A%2F%2Flink.springer.com%2Fchapter%2F10.1007%2F978-3-319-96142-2_2&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-Damas-and-Milner-1982-17"><span class="mw-cite-backlink">^ <a href="#cite_ref-Damas-and-Milner-1982_17-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Damas-and-Milner-1982_17-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFDamasMilner1982" class="citation cs2">Damas, Luis; Milner, Robin (1982), "Principal type-schemes for functional programs", <a rel="nofollow" class="external text" href="http://groups.csail.mit.edu/pag/6.883/readings/p207-damas.pdf"><i>POPL '82: Proceedings of the 9th ACM SIGPLAN-SIGACT symposium on principles of programming languages</i></a> <span class="cs1-format">(PDF)</span>, ACM, pp.&#160;<span class="nowrap">207–</span>212</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=bookitem&amp;rft.atitle=Principal+type-schemes+for+functional+programs&amp;rft.btitle=POPL+%2782%3A+Proceedings+of+the+9th+ACM+SIGPLAN-SIGACT+symposium+on+principles+of+programming+languages&amp;rft.pages=%3Cspan+class%3D%22nowrap%22%3E207-%3C%2Fspan%3E212&amp;rft.pub=ACM&amp;rft.date=1982&amp;rft.aulast=Damas&amp;rft.aufirst=Luis&amp;rft.au=Milner%2C+Robin&amp;rft_id=http%3A%2F%2Fgroups.csail.mit.edu%2Fpag%2F6.883%2Freadings%2Fp207-damas.pdf&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-18">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFMilner1978" class="citation cs2">Milner, Robin (1978), "A Theory of Type Polymorphism in Programming", <i>Journal of Computer and System Sciences</i>, <b>17</b> (3): <span class="nowrap">348–</span>375, <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1016%2F0022-0000%2878%2990014-4">10.1016/0022-0000(78)90014-4</a></span>, <a href="/wiki/Hdl_(identifier)" class="mw-redirect" title="Hdl (identifier)">hdl</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://hdl.handle.net/20.500.11820%2Fd16745d7-f113-44f0-a7a3-687c2b709f66">20.500.11820/d16745d7-f113-44f0-a7a3-687c2b709f66</a></span></cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Journal+of+Computer+and+System+Sciences&amp;rft.atitle=A+Theory+of+Type+Polymorphism+in+Programming&amp;rft.volume=17&amp;rft.issue=3&amp;rft.pages=%3Cspan+class%3D%22nowrap%22%3E348-%3C%2Fspan%3E375&amp;rft.date=1978&amp;rft_id=info%3Ahdl%2F20.500.11820%2Fd16745d7-f113-44f0-a7a3-687c2b709f66&amp;rft_id=info%3Adoi%2F10.1016%2F0022-0000%2878%2990014-4&amp;rft.aulast=Milner&amp;rft.aufirst=Robin&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-19"><span class="mw-cite-backlink"><b><a href="#cite_ref-19">^</a></b></span> <span class="reference-text">Center, Artificiał Intelligence. <a rel="nofollow" class="external text" href="https://www.sri.com/sites/default/files/uploads/publications/pdf/511.pdf">Parsing and type inference for natural and computer languages</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20120704032805/https://www.sri.com/sites/default/files/uploads/publications/pdf/511.pdf">Archived</a> 2012-07-04 at the <a href="/wiki/Wayback_Machine" title="Wayback Machine">Wayback Machine</a>. Diss. Stanford University, 1989.</span> </li> <li id="cite_note-20"><span class="mw-cite-backlink"><b><a href="#cite_ref-20">^</a></b></span> <span class="reference-text">Emele, Martin C., and Rémi Zajac. "<a rel="nofollow" class="external text" href="https://aclanthology.info/pdf/C/C90/C90-3052.pdf">Typed unification grammars</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20180205072400/https://aclanthology.info/pdf/C/C90/C90-3052.pdf">Archived</a> 2018-02-05 at the <a href="/wiki/Wayback_Machine" title="Wayback Machine">Wayback Machine</a>." Proceedings of the 13th conference on Computational linguistics-Volume 3. Association for Computational Linguistics, 1990.</span> </li> <li id="cite_note-21"><span class="mw-cite-backlink"><b><a href="#cite_ref-21">^</a></b></span> <span class="reference-text">Pareschi, Remo. "<a rel="nofollow" class="external text" href="https://www.era.lib.ed.ac.uk/bitstream/handle/1842/19215/PareschiR_1989redux.pdf?sequence=1">Type-driven natural language analysis</a>." (1988).</span> </li> <li id="cite_note-22"><span class="mw-cite-backlink"><b><a href="#cite_ref-22">^</a></b></span> <span class="reference-text">Fisher, Kathleen, et al. "Fisher, Kathleen, et al. "<a rel="nofollow" class="external text" href="https://www.cs.princeton.edu/~dpw/papers/learningpopl08-final.pdf">From dirt to shovels: fully automatic tool generation from ad hoc data</a>." ACM SIGPLAN Notices. Vol. 43. No. 1. ACM, 2008." ACM SIGPLAN Notices. Vol. 43. No. 1. ACM, 2008.</span> </li> <li id="cite_note-23"><span class="mw-cite-backlink"><b><a href="#cite_ref-23">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFLappinShieber2007" class="citation journal cs1">Lappin, Shalom; Shieber, Stuart M. (2007). <a rel="nofollow" class="external text" href="https://dash.harvard.edu/bitstream/handle/1/2031673/MachineLearning.pdf?sequence=3">"Machine learning theory and practice as a source of insight into universal grammar"</a> <span class="cs1-format">(PDF)</span>. <i>Journal of Linguistics</i>. <b>43</b> (2): <span class="nowrap">393–</span>427. <a href="/wiki/Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1017%2Fs0022226707004628">10.1017/s0022226707004628</a>. <a href="/wiki/S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&#160;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:215762538">215762538</a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&amp;rft.genre=article&amp;rft.jtitle=Journal+of+Linguistics&amp;rft.atitle=Machine+learning+theory+and+practice+as+a+source+of+insight+into+universal+grammar&amp;rft.volume=43&amp;rft.issue=2&amp;rft.pages=%3Cspan+class%3D%22nowrap%22%3E393-%3C%2Fspan%3E427&amp;rft.date=2007&amp;rft_id=info%3Adoi%2F10.1017%2Fs0022226707004628&amp;rft_id=https%3A%2F%2Fapi.semanticscholar.org%2FCorpusID%3A215762538%23id-name%3DS2CID&amp;rft.aulast=Lappin&amp;rft.aufirst=Shalom&amp;rft.au=Shieber%2C+Stuart+M.&amp;rft_id=https%3A%2F%2Fdash.harvard.edu%2Fbitstream%2Fhandle%2F1%2F2031673%2FMachineLearning.pdf%3Fsequence%3D3&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> <li id="cite_note-Shieber1992-24"><span class="mw-cite-backlink"><b><a href="#cite_ref-Shieber1992_24-0">^</a></b></span> <span class="reference-text"><link rel="mw-deduplicated-inline-style" href="mw-data:TemplateStyles:r1238218222" /><cite id="CITEREFStuart_M._Shieber1992" class="citation book cs1">Stuart M. Shieber (1992). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=QcYl_ylrHmcC&amp;q=%22type+inference%22"><i>Constraint-based Grammar Formalisms: Parsing and Type Inference for Natural and Computer Languages</i></a>. MIT Press. <a href="/wiki/ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&#160;<a href="/wiki/Special:BookSources/978-0-262-19324-5" title="Special:BookSources/978-0-262-19324-5"><bdi>978-0-262-19324-5</bdi></a>.</cite><span title="ctx_ver=Z39.88-2004&amp;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&amp;rft.genre=book&amp;rft.btitle=Constraint-based+Grammar+Formalisms%3A+Parsing+and+Type+Inference+for+Natural+and+Computer+Languages&amp;rft.pub=MIT+Press&amp;rft.date=1992&amp;rft.isbn=978-0-262-19324-5&amp;rft.au=Stuart+M.+Shieber&amp;rft_id=https%3A%2F%2Fbooks.google.com%2Fbooks%3Fid%3DQcYl_ylrHmcC%26q%3D%2522type%2Binference%2522&amp;rfr_id=info%3Asid%2Fen.wikipedia.org%3AType+inference" class="Z3988"></span></span> </li> </ol></div></div> <div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/w/index.php?title=Type_inference&amp;action=edit&amp;section=11" title="Edit section: External links"><span>edit</span></a><span class="mw-editsection-bracket">]</span></span></div> <ul><li><a rel="nofollow" class="external text" href="http://www.cis.upenn.edu/~bcpierce/types/archives/1988/msg00042.html">Archived e-mail message</a> by Roger Hindley, explains history of type inference</li> <li><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/document?repid=rep1&amp;type=pdf&amp;doi=7775e9c89fdf64b677b091259393a0f26698d0ee">Polymorphic Type Inference</a> by Michael Schwartzbach, gives an overview of Polymorphic type inference.</li> <li><a rel="nofollow" class="external text" href="http://lucacardelli.name/Papers/BasicTypechecking.pdf">Basic Typechecking</a> paper by Luca Cardelli, describes algorithm, includes implementation in <a href="/wiki/Modula-2" title="Modula-2">Modula-2</a></li> <li><a rel="nofollow" class="external text" href="http://dysphoria.net/2009/06/28/hindley-milner-type-inference-in-scala/">Implementation</a> of Hindley–Milner type inference in <a href="/wiki/Scala_(programming_language)" title="Scala (programming language)">Scala</a>, by Andrew Forrest (retrieved July 30, 2009)</li> <li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20070218103011/http://www.cs.berkeley.edu/~nikitab/courses/cs263/hm.html">Implementation of Hindley-Milner in Perl 5, by Nikita Borisov</a> at the <a href="/wiki/Wayback_Machine" title="Wayback Machine">Wayback Machine</a>&#32;(archived February 18, 2007)</li> <li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20090101030825/http://www.codecommit.com/blog/scala/what-is-hindley-milner-and-why-is-it-cool">What is Hindley-Milner? (and why is it cool?)</a> Explains Hindley–Milner, examples in Scala</li></ul> <!-- NewPP limit report Parsed by mw‐api‐int.codfw.main‐5f6dc849d4‐lhpsg Cached time: 20250306131821 Cache expiry: 2592000 Reduced expiry: false Complications: [vary‐revision‐sha1, show‐toc] CPU time usage: 0.551 seconds Real time usage: 0.677 seconds Preprocessor visited node count: 2308/1000000 Post‐expand include size: 51169/2097152 bytes Template argument size: 2419/2097152 bytes Highest expansion depth: 15/100 Expensive parser function count: 54/500 Unstrip recursion depth: 1/20 Unstrip post‐expand size: 94629/5000000 bytes Lua time usage: 0.383/10.000 seconds Lua memory usage: 24628429/52428800 bytes Number of Wikibase entities loaded: 0/400 --> <!-- Transclusion expansion time report (%,ms,calls,template) 100.00% 606.346 1 -total 30.61% 185.597 1 Template:Reflist 16.85% 102.152 4 Template:Cite_book 16.56% 100.389 1 Template:Type_systems 16.03% 97.199 1 Template:Sidebar 14.49% 87.847 1 Template:Short_description 14.36% 87.067 1 Template:Wt 8.41% 50.978 2 Template:Pagetype 7.46% 45.226 1 Template:More_citations_needed_section 6.74% 40.851 1 Template:More_citations_needed --> <!-- Saved in parser cache with key enwiki:pcache:279690:|#|:idhash:canonical and timestamp 20250306131821 and revision id 1238605275. Rendering was triggered because: api-parse --> </div><!--esi <esi:include src="/esitest-fa8a495983347898/content" /> --><noscript><img src="https://login.wikimedia.org/wiki/Special:CentralAutoLogin/start?useformat=desktop&amp;type=1x1&amp;usesul3=0" alt="" width="1" height="1" style="border: none; position: absolute;"></noscript> <div class="printfooter" data-nosnippet="">Retrieved from "<a dir="ltr" href="https://en.wikipedia.org/w/index.php?title=Type_inference&amp;oldid=1238605275">https://en.wikipedia.org/w/index.php?title=Type_inference&amp;oldid=1238605275</a>"</div></div> <div id="catlinks" class="catlinks" data-mw="interface"><div id="mw-normal-catlinks" class="mw-normal-catlinks"><a href="/wiki/Help:Category" title="Help:Category">Categories</a>: <ul><li><a href="/wiki/Category:Type_inference" title="Category:Type inference">Type inference</a></li><li><a href="/wiki/Category:Type_systems" title="Category:Type systems">Type systems</a></li><li><a href="/wiki/Category:Type_theory" title="Category:Type theory">Type theory</a></li><li><a href="/wiki/Category:Inference" title="Category:Inference">Inference</a></li></ul></div><div id="mw-hidden-catlinks" class="mw-hidden-catlinks mw-hidden-cats-hidden">Hidden categories: <ul><li><a href="/wiki/Category:Webarchive_template_wayback_links" title="Category:Webarchive template wayback links">Webarchive template wayback links</a></li><li><a href="/wiki/Category:Articles_with_short_description" title="Category:Articles with short description">Articles with short description</a></li><li><a href="/wiki/Category:Short_description_is_different_from_Wikidata" title="Category:Short description is different from Wikidata">Short description is different from Wikidata</a></li><li><a href="/wiki/Category:Articles_needing_additional_references_from_November_2020" title="Category:Articles needing additional references from November 2020">Articles needing additional references from November 2020</a></li><li><a href="/wiki/Category:All_articles_needing_additional_references" title="Category:All articles needing additional references">All articles needing additional references</a></li><li><a href="/wiki/Category:All_articles_with_unsourced_statements" title="Category:All articles with unsourced statements">All articles with unsourced statements</a></li><li><a href="/wiki/Category:Articles_with_unsourced_statements_from_February_2021" title="Category:Articles with unsourced statements from February 2021">Articles with unsourced statements from February 2021</a></li><li><a href="/wiki/Category:Articles_with_example_C_code" title="Category:Articles with example C code">Articles with example C code</a></li><li><a href="/wiki/Category:Articles_with_example_Haskell_code" title="Category:Articles with example Haskell code">Articles with example Haskell code</a></li><li><a href="/wiki/Category:Articles_with_example_JavaScript_code" title="Category:Articles with example JavaScript code">Articles with example JavaScript code</a></li></ul></div></div> </div> </main> </div> <div class="mw-footer-container"> <footer id="footer" class="mw-footer" > <ul id="footer-info"> <li id="footer-info-lastmod"> This page was last edited on 4 August 2024, at 19:02<span class="anonymous-show">&#160;(UTC)</span>.</li> <li id="footer-info-copyright">Text is available under the <a href="/wiki/Wikipedia:Text_of_the_Creative_Commons_Attribution-ShareAlike_4.0_International_License" title="Wikipedia:Text of the Creative Commons Attribution-ShareAlike 4.0 International License">Creative Commons Attribution-ShareAlike 4.0 License</a>; additional terms may apply. By using this site, you agree to the <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Terms_of_Use" class="extiw" title="foundation:Special:MyLanguage/Policy:Terms of Use">Terms of Use</a> and <a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy" class="extiw" title="foundation:Special:MyLanguage/Policy:Privacy policy">Privacy Policy</a>. Wikipedia® is a registered trademark of the <a rel="nofollow" class="external text" href="https://wikimediafoundation.org/">Wikimedia Foundation, Inc.</a>, a non-profit organization.</li> </ul> <ul id="footer-places"> <li id="footer-places-privacy"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Privacy_policy">Privacy policy</a></li> <li id="footer-places-about"><a href="/wiki/Wikipedia:About">About Wikipedia</a></li> <li id="footer-places-disclaimers"><a href="/wiki/Wikipedia:General_disclaimer">Disclaimers</a></li> <li id="footer-places-contact"><a href="//en.wikipedia.org/wiki/Wikipedia:Contact_us">Contact Wikipedia</a></li> <li id="footer-places-wm-codeofconduct"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Universal_Code_of_Conduct">Code of Conduct</a></li> <li id="footer-places-developers"><a href="https://developer.wikimedia.org">Developers</a></li> <li id="footer-places-statslink"><a href="https://stats.wikimedia.org/#/en.wikipedia.org">Statistics</a></li> <li id="footer-places-cookiestatement"><a href="https://foundation.wikimedia.org/wiki/Special:MyLanguage/Policy:Cookie_statement">Cookie statement</a></li> <li id="footer-places-mobileview"><a href="//en.m.wikipedia.org/w/index.php?title=Type_inference&amp;mobileaction=toggle_view_mobile" class="noprint stopMobileRedirectToggle">Mobile view</a></li> </ul> <ul id="footer-icons" class="noprint"> <li id="footer-copyrightico"><a href="https://wikimediafoundation.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><picture><source media="(min-width: 500px)" srcset="/static/images/footer/wikimedia-button.svg" width="84" height="29"><img src="/static/images/footer/wikimedia.svg" width="25" height="25" alt="Wikimedia Foundation" lang="en" loading="lazy"></picture></a></li> <li id="footer-poweredbyico"><a href="https://www.mediawiki.org/" class="cdx-button cdx-button--fake-button cdx-button--size-large cdx-button--fake-button--enabled"><picture><source media="(min-width: 500px)" srcset="/w/resources/assets/poweredby_mediawiki.svg" width="88" height="31"><img src="/w/resources/assets/mediawiki_compact.svg" alt="Powered by MediaWiki" lang="en" width="25" height="25" loading="lazy"></picture></a></li> </ul> </footer> </div> </div> </div> <div class="vector-header-container vector-sticky-header-container"> <div id="vector-sticky-header" class="vector-sticky-header"> <div class="vector-sticky-header-start"> <div class="vector-sticky-header-icon-start vector-button-flush-left vector-button-flush-right" aria-hidden="true"> <button class="cdx-button cdx-button--weight-quiet cdx-button--icon-only vector-sticky-header-search-toggle" tabindex="-1" data-event-name="ui.vector-sticky-search-form.icon"><span class="vector-icon mw-ui-icon-search mw-ui-icon-wikimedia-search"></span> <span>Search</span> </button> </div> <div role="search" class="vector-search-box-vue vector-search-box-show-thumbnail vector-search-box"> <div class="vector-typeahead-search-container"> <div class="cdx-typeahead-search cdx-typeahead-search--show-thumbnail"> <form action="/w/index.php" id="vector-sticky-search-form" class="cdx-search-input cdx-search-input--has-end-button"> <div class="cdx-search-input__input-wrapper" data-search-loc="header-moved"> <div class="cdx-text-input cdx-text-input--has-start-icon"> <input class="cdx-text-input__input" type="search" name="search" placeholder="Search Wikipedia"> <span class="cdx-text-input__icon cdx-text-input__start-icon"></span> </div> <input type="hidden" name="title" value="Special:Search"> </div> <button class="cdx-button cdx-search-input__end-button">Search</button> </form> </div> </div> </div> <div class="vector-sticky-header-context-bar"> <nav aria-label="Contents" class="vector-toc-landmark"> <div id="vector-sticky-header-toc" class="vector-dropdown mw-portlet mw-portlet-sticky-header-toc vector-sticky-header-toc vector-button-flush-left" > <input type="checkbox" id="vector-sticky-header-toc-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-vector-sticky-header-toc" class="vector-dropdown-checkbox " aria-label="Toggle the table of contents" > <label id="vector-sticky-header-toc-label" for="vector-sticky-header-toc-checkbox" class="vector-dropdown-label cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only " aria-hidden="true" ><span class="vector-icon mw-ui-icon-listBullet mw-ui-icon-wikimedia-listBullet"></span> <span class="vector-dropdown-label-text">Toggle the table of contents</span> </label> <div class="vector-dropdown-content"> <div id="vector-sticky-header-toc-unpinned-container" class="vector-unpinned-container"> </div> </div> </div> </nav> <div class="vector-sticky-header-context-bar-primary" aria-hidden="true" ><span class="mw-page-title-main">Type inference</span></div> </div> </div> <div class="vector-sticky-header-end" aria-hidden="true"> <div class="vector-sticky-header-icons"> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only" id="ca-talk-sticky-header" tabindex="-1" data-event-name="talk-sticky-header"><span class="vector-icon mw-ui-icon-speechBubbles mw-ui-icon-wikimedia-speechBubbles"></span> <span></span> </a> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only" id="ca-subject-sticky-header" tabindex="-1" data-event-name="subject-sticky-header"><span class="vector-icon mw-ui-icon-article mw-ui-icon-wikimedia-article"></span> <span></span> </a> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only" id="ca-history-sticky-header" tabindex="-1" data-event-name="history-sticky-header"><span class="vector-icon mw-ui-icon-wikimedia-history mw-ui-icon-wikimedia-wikimedia-history"></span> <span></span> </a> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only mw-watchlink" id="ca-watchstar-sticky-header" tabindex="-1" data-event-name="watch-sticky-header"><span class="vector-icon mw-ui-icon-wikimedia-star mw-ui-icon-wikimedia-wikimedia-star"></span> <span></span> </a> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only" id="ca-edit-sticky-header" tabindex="-1" data-event-name="wikitext-edit-sticky-header"><span class="vector-icon mw-ui-icon-wikimedia-wikiText mw-ui-icon-wikimedia-wikimedia-wikiText"></span> <span></span> </a> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only" id="ca-ve-edit-sticky-header" tabindex="-1" data-event-name="ve-edit-sticky-header"><span class="vector-icon mw-ui-icon-wikimedia-edit mw-ui-icon-wikimedia-wikimedia-edit"></span> <span></span> </a> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--icon-only" id="ca-viewsource-sticky-header" tabindex="-1" data-event-name="ve-edit-protected-sticky-header"><span class="vector-icon mw-ui-icon-wikimedia-editLock mw-ui-icon-wikimedia-wikimedia-editLock"></span> <span></span> </a> </div> <div class="vector-sticky-header-buttons"> <button class="cdx-button cdx-button--weight-quiet mw-interlanguage-selector" id="p-lang-btn-sticky-header" tabindex="-1" data-event-name="ui.dropdown-p-lang-btn-sticky-header"><span class="vector-icon mw-ui-icon-wikimedia-language mw-ui-icon-wikimedia-wikimedia-language"></span> <span>16 languages</span> </button> <a href="#" class="cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--weight-quiet cdx-button--action-progressive" id="ca-addsection-sticky-header" tabindex="-1" data-event-name="addsection-sticky-header"><span class="vector-icon mw-ui-icon-speechBubbleAdd-progressive mw-ui-icon-wikimedia-speechBubbleAdd-progressive"></span> <span>Add topic</span> </a> </div> <div class="vector-sticky-header-icon-end"> <div class="vector-user-links"> </div> </div> </div> </div> </div> <div class="mw-portlet mw-portlet-dock-bottom emptyPortlet" id="p-dock-bottom"> <ul> </ul> </div> <script>(RLQ=window.RLQ||[]).push(function(){mw.config.set({"wgHostname":"mw-web.codfw.next-5f874b7bcc-h6k9g","wgBackendResponseTime":136,"wgPageParseReport":{"limitreport":{"cputime":"0.551","walltime":"0.677","ppvisitednodes":{"value":2308,"limit":1000000},"postexpandincludesize":{"value":51169,"limit":2097152},"templateargumentsize":{"value":2419,"limit":2097152},"expansiondepth":{"value":15,"limit":100},"expensivefunctioncount":{"value":54,"limit":500},"unstrip-depth":{"value":1,"limit":20},"unstrip-size":{"value":94629,"limit":5000000},"entityaccesscount":{"value":0,"limit":400},"timingprofile":["100.00% 606.346 1 -total"," 30.61% 185.597 1 Template:Reflist"," 16.85% 102.152 4 Template:Cite_book"," 16.56% 100.389 1 Template:Type_systems"," 16.03% 97.199 1 Template:Sidebar"," 14.49% 87.847 1 Template:Short_description"," 14.36% 87.067 1 Template:Wt"," 8.41% 50.978 2 Template:Pagetype"," 7.46% 45.226 1 Template:More_citations_needed_section"," 6.74% 40.851 1 Template:More_citations_needed"]},"scribunto":{"limitreport-timeusage":{"value":"0.383","limit":"10.000"},"limitreport-memusage":{"value":24628429,"limit":52428800}},"cachereport":{"origin":"mw-api-int.codfw.main-5f6dc849d4-lhpsg","timestamp":"20250306131821","ttl":2592000,"transientcontent":false}}});});</script> <script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Article","name":"Type inference","url":"https:\/\/en.wikipedia.org\/wiki\/Type_inference","sameAs":"http:\/\/www.wikidata.org\/entity\/Q586459","mainEntity":"http:\/\/www.wikidata.org\/entity\/Q586459","author":{"@type":"Organization","name":"Contributors to Wikimedia projects"},"publisher":{"@type":"Organization","name":"Wikimedia Foundation, Inc.","logo":{"@type":"ImageObject","url":"https:\/\/www.wikimedia.org\/static\/images\/wmf-hor-googpub.png"}},"datePublished":"2003-07-27T11:17:52Z","dateModified":"2024-08-04T19:02:24Z","headline":"automatic detection of the data type of an expression in a programming language"}</script> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10