Questions tagged [function-signature]
80 questions
7
votes
3 answers
placing python tuples in function signature
In python there is this interesting, and very useful tool by which you can pattern match values from tuples on function signature.
def first((a, b)):
return a
x = (4, 9)
first(x)
li = [(5, 4), (8, 9)]
map(first, li)
def second(a, b):
#…

probinso
- 309
- 2
- 9
7
votes
4 answers
c++ function syntax/prototype - data type after brackets
I am very familiar with C/C++ standard function declarations. I've recently seen something like this:
int myfunction(char parameter) const
The above is only a hypothetical example and I don't even know if it makes sense. I'm referring to the part…

itsols
- 5,406
- 7
- 51
- 95
6
votes
3 answers
Specifying struct in function signature
Say I have
struct mystruct
{
};
Is there a difference between:
void foo(struct mystruct x){}
and
void foo(mystruct x){}
?

Luchian Grigore
- 253,575
- 64
- 457
- 625
6
votes
4 answers
Is it possible to retrieve the argument types from a (Functor member's) function signature for use in a template?
Assume you have a functor:
struct MyFunctor
{
bool operator ()( int value )
{
return true;
}
};
Is it possible to retrieve a functor's member's argument type for use within your template? The following is a use of this mythical…

Catskul
- 17,916
- 15
- 84
- 113
5
votes
1 answer
PHP core function arguments; manual says reference, however it accepts values
I've noticed some inconsistencies in the PHP manual; a number of core function signatures are documented to accept arguments by reference, however they accept arguments by value.
I posted a more specific question previously, and @cweiske provided a…

Dan Lugg
- 20,192
- 19
- 110
- 174
4
votes
3 answers
C++ and coverity issues
MyClass* const Func(const std::string& statename)
for this coverity is giving the error
Parse warning (PW.USELESS_TYPE_QUALIFIER_ON_RETURN_TYPE) type
qualifier on return type is meaningless .
Do we really need to remove the const here.?

Sudhakar
- 93
- 3
- 9
4
votes
2 answers
Reduce IO (Maybe (IO (Maybe a)) to IO (Maybe a)
I have a function that reads an Rsa key with the HsOpenSsl's readPrivateKey function unfortunately the signature of my function is this String -> IO (Maybe (IO Maybe RsaKey)). I need the PEM format and a Cryptonite.RSA key and I wrote the function…

Gian Laager
- 474
- 4
- 14
4
votes
4 answers
How to substitute generic anonymous functions?
Suppose there is a trait for legged animals:
trait Legged {
val legs: Int
def updateLegs(legs: Int): Legged
}
And there two such legged animals:
case class Chicken(feathers: Int, legs: Int = 2) extends Legged {
override def updateLegs(legs:…

Random42
- 8,989
- 6
- 55
- 86
4
votes
2 answers
Why these C++ cases instantiate different templates
I am trying to write some functionality where I need to save different functions and later extract their arguments' types. So I'm using the function signature as template parameter. But I get somewhat unexpected results.
Here's the code:
#include…

Pavel
- 73
- 5
4
votes
2 answers
Specialized template for function signature
In that test code:
#include
#include
using namespace std;
template class Signal;
template
class Signal
{
public:
Signal(T (*ptr)(U))
{
}
};
void Print(string const&…

Sancho
- 1,288
- 2
- 25
- 50
3
votes
3 answers
Type constraints with multiple type variables in Haskell function signature
I have been searching on documentations and wikis for Haskell's type constraints in function signatures. Unfortunately, I wasn't able to find a satisfactory answer.
At this time, I consider myself as a beginner, so I would like to ask your…

NickS1
- 496
- 1
- 6
- 19
3
votes
1 answer
How to distinguish different functions signature with conditional type checks?
I'd like to be distinguish the following function types in conditional type checks:
type SyncFn = () => void;
type AsyncFn = (data: number) => Promise;
type SyncFnWithArg = (data: number) => void;
So I can then use the KeyOfType that @Titian…

awdk
- 1,477
- 12
- 17
3
votes
1 answer
When is it safe to leave out a const from a function's parametrization?
Many times I write C++ functions I seem to use many more const modifiers than other folks.
For example, I write Excel .xlsx files and I use LibXL library for this, and the documentation mentions a function like this:
bool writeNum(int row, int col,…

Gyula Sámuel Karli
- 3,118
- 2
- 15
- 18
3
votes
2 answers
How do I declare an optional parameter in a signature?
Let's say I have
use v5.026;
use feature 'signatures';
sub foo ($opt1, $opt2) {
say $opt1 if $opt2;
}
main::foo(1,2);
main::foo(1);
Now I want to call foo with and without opt2:
foo(1); # not currently accepted
foo(1,2); # works fine

Evan Carroll
- 78,363
- 46
- 261
- 468
3
votes
2 answers
Pass default value instead of reference
I have a function like this (using PHP 7.1):
function myfunction(&$first = null, $second = null)
{ // do something
}
What I want to achieve is to pass null as the first parameter and pass something as the second parameter:
myfunction(null,…

Roland Seuhs
- 1,878
- 4
- 27
- 51