Question: I would like to write a function convert type `string -> nat` in `coq`.
Where the string contents only number will return `nat` otherwise it will return `0` for the alphabet or alphabet with number or any cases that is not contain number (for example: ', -, ...).

For example:

`"0", "1", "2", "3", ... "99",..` will return : `0, 1, 2, 3, ..., 99, ...`

`"a", "bc", "..0d"`,... will return : `0`

Am I able to write this function in `Coq`?

I tried by myself but I do not know how can I convert just the number and not the alphabet like my example?

```
Require Import Ascii String.

  Definition nat_of_string (s : string) : nat :=
    match s with
      | EmptyString  => 0
      | String (s) _ => nat_of_ascii s
    end.

```

Answer: 
You can define the default function as private method :

```dart
_defaultTransform(Something v) => v;
void _doSomething(List<Something> numbers, 
                  [transform(Something element) = _defaultTransform]) {...}

```

Or check argument like this :

```dart
void _doSomething(List<Something> numbers, [transform(Something element)]) {
  if (!?transform) transform = (v) => v;
  ...
}

```

Or like [Ladicek](https://stackoverflow.com/users/742081/ladicek) suggests :

```dart
void _doSomething(List<Something> numbers, [transform(Something element)]) {
 transform ??= (v) => v;
  ...
}

```
if you want to initialize a Function parameter that is also a field of your class I suggest:

```
class MyClass{
  Function myFunc;
  MyClass({this.myFunc = _myDefaultFunc}){...}
  static _myDefaultFunc(){...}
}

```

Or more suitable:

```
typedef SpecialFunction = ReturnType Function(
                              FirstParameterType firstParameter, 
                              SecondParameterType secondParameter);

class MyClass{
  SpecialFunction myFunc;
  MyClass({this.myFunc = _myDefaultFunc}){...}
  static ReturnType _myDefaultFunc(FirstParameterType firstParameter, 
                                   SecondParameterType secondParameter){...}
}

```