Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6996817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:12:21+00:00 2026-05-27T20:12:21+00:00

First, let us assume that local type inference is the sort of type inference

  • 0

First, let us assume that local type inference is the sort of type inference found in Scala and C#. Scala local type inference is explained here: http://www.scala-lang.org/node/127

Also, let us assume, that a definition such as

     fact 0 = 1
     fact n = n * fact(n-1)

would count as local type inference — that is, type inference here is local to function fact. Scala does not permit such a type inferece; still let us count it as local.

The question, then, is whether anyone has a practical example of at least 2 mutually-recursive functions (or any other non-locality at your discretion) that derive some benefit from type inference? Please do not post silly examples such as:

    odd 0 = false
    odd n = even(n-1)

    even 0 = true
    even n = odd(n-1)

I suspect that non-silly, practical examples arise in parses. Also, please could you explain the benefits a programmer could derive from such uses of non-local type inference?

UPDATE:

I appreciate any example of insufficiency of local type inference and the need for full-blown type inference.

  1. Your Haskell or OCaml example may be 90% correct, because you are only 90% understand the term “non-local type inference”. Still, you have to understand Haskell (or OCaml) type inference.

  2. Your example may be written on Scala or C#. Please point out that compliler really has enough information to infer the type, but the type can not be inferred due to language specification or due to local-only nature of type inference in Scala or C#.

// And again, feel free to correct my english.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:12:22+00:00Added an answer on May 27, 2026 at 8:12 pm

    I’m not completely sure what examples would count for you, because you mention both non-locality and mutual recursion, and I don’t understand whether an example that exhibits just non-locality is enough.

    I will say that a common technique in Haskell is to write functions whose return type is a class-constrained type variable not mentioned in the argument types. For example, like this:

    foo :: (Result a) => String -> a
    foo = toResult . transform  -- transform :: String -> String
    
    class Result a where
       toResult :: String -> a
    
    -- Example implementation of Result class—with this, callers that 
    -- expect foo to return an Integer will get the length of the result
    -- of transform.
    instance Result Integer where
       toResult = length
    

    In this case, the concrete type of the result of any call to foo is determined by type inference at the calling site. I.e., the return type of any call to foo is inferred from information not present in the definition of foo.

    One practical example of this is Haskell’s regular expression libraries. The interface uses this pattern so that, instead of having a bunch of different regexp matching functions that return different types, there is a regexp matching operator that is polymorphic on the return type as shown above, and thus the caller’s type inference controls what is returned.

    So for example, if you do regexp matching in a calling context where the inferred return type is an integer, you get back number of matches. If the calling context expects a boolean, you get True if there were any matches. If the calling context expects a list of strings, you get a list of the substrings that matched the regexp. A bunch of other return type-specific behaviors are defined—and you can define your own for arbitrary return types by implementing your own instances of the library’s type class for results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume that you are working at the first version of a new Django
First let me say that I really feel directionless on this question. I am
First let me state that, despite being a fairly new practitioner of TDD, I'm
First let me say that I did see this article: How to remove AspxAutoDetectCookieSupport
Let me first put the code snippets here. I am just using the ASP.NET
Let's assume that we have a simple matrix 3rows x 7cols. The matrix includes
Let's assume that we have following jQuery plugins (each of them in separate files):
Let's say you have a bug that was found in functional testing of a
Let's for a moment assume that you're programming in a language that uses camelcase
Let me first say that I have quite a lot of Java experience, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.