-1

One of the nice features of IPython is that I can inspect a function.

In [1]: def inc(x):
   ...:     """Increments a number"""
   ...:     return x+1
   ...: 

In [2]: inc?
Type:        function
String form: <function inc at 0x105f19758>
File:        /Users/christophercaycock/<ipython-input-1-f192044ce250>
Definition:  inc(x)
Docstring:   Increments a number

I can do this because there is can only ever be one definition of inc, though it may operate differently depending on the type I provide it.

Many statically typed languages have overloading, where I can perform different actions depending on the type at compile time. In these languages, there may be multiple definitions of inc.

I was wondering if there are interactive shells that can handle this. I checked IHaskell, but I couldn't actually find an example in their documentation.

I'm just curious as to whether it's even possible (and what it would look like) to provide interactive help in the face of overloading.

  • 4
    Have you used an IDE like Visual Studio? They can show you the documentation of overloaded functions. – svick May 21 '15 at 2:11
  • Haskell doen't allow overloading which is presumebly why you can't find anything in IHaskell – jk. Aug 20 '18 at 14:02
  • though admitedly with GHCI you can inspect types with :t – jk. Aug 20 '18 at 14:03
0

Powershell handles this by showing the overloaded definitions when typing the command into the console:

A simple example is the GetProcessesByName method from the System.Diagnostics.Process class. It has two overloads: one in which I pass only the process name and the other where I pass the process name and the name of the computer. This overload definition gives me the ability to return processes locally or remotely. Here are the overload definitions:

PS C:\Users\mredw> [System.Diagnostics.Process]::GetProcessesByName

OverloadDefinitions                                                                  

-------------------                                                                 

static System.Diagnostics.Process[] GetProcessesByName(string processName)          

static System.Diagnostics.Process[] GetProcessesByName(string processName, string machineName)              

References

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.