[Question]
  [
## Background
The number of values for a given type is called the *cardinality* of that type, and that of type T is written as `|T|`.
Haskell and a few other languages have a certain set of enum types, each of which has a small finite number of values (the exact names vary, so this challenge uses some arbitrarily chosen names).
```
Name  | Cardinality
------+-------------
Never | 0
Unit  | 1
Bool  | 2 (true or false)
Order | 3 (LT, EQ, or GT)
```
And they also have some derived types which have one or more *type parameters*. Their cardinality depends on which types they get as parameters (written as `T` and `U` in the table below). `Func(T,U)` represents the function commonly written as `T -> U`, i.e. a function that takes a parameter of type T and returns a value of type U.
```
Name(Params) | Cardinality
-------------+-------------
Option(T)    | |T| + 1     (some value from T, or absence)
Either(T,U)  | |T| + |U|   (some value from T or some value from U)
Pair(T,U)    | |T| * |U|   (any combination of values from T and U)
Func(T,U)    | |U| ** |T|  (any combination of U for every value of T)
```
Note: A "function" here is to be understood as a mathematical concept rather than a programming one. A mathematical function `Func(T,U)` maps every possible value of T to some value of U, disregarding the "how". For programmers, it is OK to think of it as functions of the form of (in Haskell-like pseudocode):
```
\(x :: T) -> case x of
  value1OfT -> someValue1OfU
  value2OfT -> someValue2OfU
  ...
  valueXOfT -> someValueXOfU
```
with all cases provided.
For example, `Option(Never)` has cardinality 1, and `Func(Bool,Order)` has cardinality `3**2 = 9`. `Func(Never,Never)` has cardinality 1; `0**0` is defined to be 1 in this system.
A type parameter can itself be a derived type, so `Pair(Func(Never,Never),Pair(Either(Bool,Bool),Option(Order)))` is also a valid type, which has cardinality of `(0**0) * ((2+2) * (3+1)) = 16`.
For this challenge, assume that no types other than the 8 presented above are available.
## Challenge
Given a string that represents a valid type in this system, output its cardinality. You can assume the input does not contain spaces.
Standard [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") rules apply. The shortest code in bytes wins.
## Test cases
```
Never -> 0
Unit -> 1
Bool -> 2
Order -> 3
Func(Never,Never) -> 1
Func(Unit,Never) -> 0
Option(Unit) -> 2
Option(Order) -> 4
Either(Bool,Bool) -> 4
Either(Bool,Order) -> 5
Pair(Bool,Order) -> 6
Pair(Func(Never,Never),Pair(Either(Bool,Bool),Option(Order))) -> 16
Func(Func(Order,Order),Order) -> 7625597484987
```
  
[Answer]
# [Proton](https://github.com/alexander-liao/proton), 80 bytes
```
Never,Unit,Bool,Order=0..4
Option=(1+)
Either=(+)
Pair=(*)
Func=(x,y)=>y**x
eval
```
[Try it online!](https://tio.run/##ZZDNTsMwEITP3aewevIGEyUlP@3BPVQqR8qFBwhgqZYi2zLunxDPnsbrSC1wWY0@b2Zn4rwN1gzDizoqL96MDmJjbS92/lN5WeR5BTsXtDWSlw8IWx32I@ejfO30KDKE54P5kPwsLijXlyw7gzp2/XDa616xkn3DrBPsnUmmjTsEjvmX63Xgc/a4ZnOEmfPaBB53BItf8g4RflKguFNATBVVCTFaVAugfFE@0X2e8tPEtEuYCt1oMZUhjpNTImRIqJpa8tuPIF5T5b@0SfRfCEH43ikOFL/OYcrapLA06GHyvzvTNou6XrXVslot2ys "Proton – Try It Online")
This solution is a whole lot shorter in Proton. Original Python solution included below.
# [Python 3](https://docs.python.org/3/), 106 bytes
```
Never=0
Unit=1
Bool=2
Order=3
Option=1 .__add__
Either=int.__add__
Pair=int.__mul__
Func=int.__rpow__
eval
```
[Try it online!](https://tio.run/##ZZBNTwMhEIbP5VeQniBZm7b71ZrgwUSP1oOeN9QlWRIEwrJt/PUrDKirXibDMzPvvIP98IPR5Tw/iYtwbItetfRsh@6NUWyPTq4PtEQn66XRbIc3Xcf7vuvQg/RDKEntv9Ezl1/gfVIBPE76LQNnzTUQceFqvg5SCfziJnGLVrzAZ8yw1HbyhG5Gq6Qna3xzh9cUrawL4yT2hAcfR@E8jhqEU8zilCdnmrzHkWQ/ZumCmOUjYlqCIwLtBUSaegHH0QXd5qOB06yUCAgCqvI/kLit@OE1fMZf2iT6z0QBeKkUAy1@raPJa5PMQoBC1l@saZt9XR/b6lAdD@0n "Python 3 – Try It Online")
-3 bytes thanks to dingledooper
`__rpow__` exists so I don't even have to do `lambda x,y:y**x` so this is even more boring :D
trivial solution and I'm sure there's something both better and smarter
[Answer]
# [JavaScript (V8)](https://v8.dev/), 98 bytes
```
Never=0
Unit=1
Bool=2
Order=3
Option=x=>1+x
Either=(x,y)=>x+y
Pair=Math.imul
Func=(x,y)=>y**x
eval
```
[Try it online!](https://tio.run/##NY2xDsIgFEX39xmdoK2N1cXldTDRTeviBxAklgahoZTA12NLdDk3Ofcmd2SezdzKye38KaW78MLiHp5aOmzhbIzCA/T2tdoj9JOTRmPArq0CXKQbVk1CHSl2oYrwYNLijbmhkZ9FwXXR/F/HsgwgPFOJGz0bJRpl3mQTpNh2JCMf1Zn0FwWl6Qs "JavaScript (V8) – Try It Online")
Same idea as @hyper-neutrino, though its shorter in js
-1 byte thanks to @Arnauld
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), ~~77~~ ~~31~~ 28 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
Rv"0123>+*m ""NUBdpEPF"ykè.V
```
Byte-count more than halved and sped up a lot by porting [*@Neil*'s Charcoal answer](https://codegolf.stackexchange.com/a/236277/52210), so make sure to upvote him as well!
[Try it online](https://tio.run/##yy9OTMpM/f8/qEzJwNDI2E5bK1dBSckv1CmlwDXATaky@/AKvbD//wMSM4s03ErzkjX8UstSi3TApKYOWNg1syQjtUjDKT8/RwdEaOr4F5Rk5udp@BelABVpagIA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3l/6AyJQNDI2M7ba1cBSUlv1CnlALXADelyuzDK/TC/tfq/PdLLUst4grNyyzhcsrPz@HyL0oB8t1K85I1wFI6YFITIgJSBhPwLyjJzM8DC8E5YM2aXK6ZJRmpRRog83RABKoIVFFAYiYWAQyLdcDCGCbqoNioCXUfmAALQQ2FUgA).
**Explanation:**
```
R                            # Reverse the (implicit) input-string
 v                           # Loop over each of its characters `y`:
             "NUBdpEPF"yk    #  Get the index of `y` in "NUBdpEPF"
                             #  (which will result in -1 if it isn't present)
  "0123>+*m "            è   #  Use it to (0-base modulair) index into "0123>+*m "
                          .V #  Execute it as 05AB1E code:
                             #   `>`: Increment the top value by 1
                             #   `+`: Add the top two values together
                             #   `*`: Multiply the top two values
                             #   `m`: Take the exponent of the top two values
                             #   The digits 0-3 remain the same
                             #   ` `: No-op for not found characters / index -1
                             # (after which the result is output implicitly)
```
### Original (77 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)) answer:
```
”†™‰¿ëÄ‚Ñ”#ā<:Δ”íŽ‰‡¥Öˆ¦c”#vD.γd}þàÝ©NĀiã©',ý}€…(ÿ)yì®N_i>ëíðý…m+*Nè«}øvy`.V:
```
Because 05AB1E lacks both regexes and functions, this uses a brute-force replacement method wrapped in a loop. It's therefore also extremely slow the larger the integer becomes, and will fail to complete the final test cases as is.
[Try it online](https://tio.run/##yy9OTMpM/f//UcPcRw0LHrUsetSw4dD@w6sPtzxqmHV4IlBY@UijjdW5KUDW4bVH9wKlHzUsPLT08LTTbYeWJYPky1z0zm1OqT287/CCw3MPrfQ70pB5ePGhleo6h/fWPmpa86hhmcbh/ZqVh9ccWucXn2kHNHvt4Q2HgSYty9XW8ju84tDq2sM7yioT9MKs/v8PSMws0nArzUvW8EstSy3SAZOaOmBh18ySjNQiDaf8/BwdEKGp419Qkpmfp@FflAJUpKkJAA) or [verify all test cases](https://tio.run/##yy9OTMpM/V9TVmmvpPCobZKCkn3l/0cNcx81LHjUsuhRw4ZD@w@vPtzyqGHW4YlAYeUjjTZW0S4pykD24bVH9wIVPGpYeGjp4Wmn2w4tSwapKHPRO7c5pfbwvsMLDs89tNLvSEPm4cWHVqrrHN5b@6hpzaOGZRqH92tWHl5zaJ1ffKYd0PS1hzccBpq0LFdby@/wikOraw/vKKtM0Auz@l9bW6vz3y@1LLWIKzQvs4TLKT8/h8u/KAXIdyvNS9YAS@mASU2ICEgZTMC/oCQzPw8sBOeANWtyuWaWZKQWaYDM0wERqCJQRQGJmVgEMCzWAQtjmKiDYqMm1H1gAiwENRRKAQA) (the `Δ` is replaced with `[Dd#` in the test suite to speed it up slightly, so we can also verify the last test case).
**Explanation:**
```
”†™‰¿ëÄ‚Ñ”       # Push dictionary string "Never Unit Bool Order"
          #      # Split it on spaces: ["Never","Unit","Bool","Order"]
           ā     # Push a list in the range [1,length] (without popping): [1,2,3,4]
            <    # Decrease each to the range [0,length): [0,1,2,3]
             :   # Replace all "Never" with 0; "Unit" with 1; etc. in the (implicit)
                 # input-string
Δ                # Loop until the result no longer changes:
[Dd#             # (slightly faster alternative, so we'll have one iteration less:)
[                #  Start an infinite loop
 D               #   Duplicate the current string
  d              #   If it's a non-negative (>=0) integer:
   #             #    Stop the infinite loop
 ”íŽ‰‡¥Öˆ¦c”     #  Push dictionary string "Option Either Pair Func"
            #    #  Split it on spaces: ["Option","Either","Pair","Func"]
 v               #  Loop over each string `y` in this list:
  D.γd}þà        #   Get the current maximum integer in the string:
  D              #    Duplicate the string
   .γ            #    Group this string into substrings by:
     d           #     If it's a non-negative (>=0) integer
      }þ         #    After the group-by, only leave these integers
        à        #    And pop and push the maximum
         Ý       #   Pop and push a list in the range [0,max]
          ©      #   Store it in variable `®`
  NĀi            #   If the index is NOT 0 (thus not "Option"):
     ã           #    Take the cartesian product of this list
      ©          #    Store that in variable `®` instead
       ',ý      '#    And join each inner pair with "," delimiter
    }€…(ÿ)       #   After the if-statement: wrap each integer/string into parenthesis
          yì     #   And prepend the current string `y`
  ®              #   Push list `®` again
   N_i           #   If the index is 0 (thus "Option"):
      >          #    Simply increase the value by 1
     ë           #   Else:
      í          #    Reverse each pair in the list
       ðý        #    Join each pair with space delimiter
         …m+*    #    Push string "m+*"
             Nè  #    Index the loop-index into it (0-based modulair)
               « #    Append it to each string
     }ø          #   After the if-else statement: zip to create pairs of the two lists
       v         #   Loop over each pair `y` in this list:
        y        #    Push the pair `y`
         `       #    Pop and push both values separated to the stack
          .V     #    Execute the second string as 05AB1E code, resulting in an integer
            :    #    Replace the first string to this integer
                 # (after which the result is output implicitly)
```
[See this 05AB1E tip of mine (section *How to use the dictionary?*)](https://codegolf.stackexchange.com/a/166851/52210) to understand why `”†™‰¿ëÄ‚Ñ”` is `"Never Unit Bool Order"` and `”íŽ‰‡¥Öˆ¦c”` is `"Option Either Pair Func"`.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 129 bytes
```
Or
Q
{T`NUBQ)(l`0-3;_
O(\d+);
$.(_$1*
E(\d+),(\d+);
$.($1*_$2*
P(\d+),(\d+);
$.($1*$2*
F(\d+)
F$1*
(F_*)_(,\d+;)
P$1$2$2
F,\d+;
1
```
[Try it online!](https://tio.run/##bY4xD4IwEIX3@x0dWqxGcGQjoSOFRDaTQqSJTQiYprr447E9UUNgeZf33d27s9qZoY2nSVqo4HVuijqrGO2b4/6UKpD00u1YCuRAFYkjyNHzP/VQkSSCcqMRuEACIixToSKmKPckZVCSmCQkAYEe/AuFfmoL9WAcZOPYg7Sd9@IxXCm2OCr7kDD2BfLuzDgg@hlcZpAbd9OWhjweZEnmobI1G2B1mCNeJfLFRTb/h4JoDp3LGw "Retina – Try It Online") Link includes test cases. Explanation:
```
Or
Q
```
Change `Order` to `Qder` to avoid confusion with `Option`, and also because `O` has special meaning for Transliterate.
```
{
```
Repeat the remaining transformations until the desired result is obtained. (The transliteration does not need to be repeated but it's golfer to share the ```.)
```
T`NUBQ)(l`0-3;_
```
Transliterate the `Never`, `Unit`, `Bool` and `Qder` to `0` to `3` respectively, transliterate the `)` to `;` for ease of matching, and delete the lower case letters and `(`.
```
O(\d+);
$.(_$1*
```
Handle `Option` by incrementing the value.
```
E(\d+),(\d+);
$.($1*_$2*
```
Handle `Either` by taking the sum of the values.
```
P(\d+),(\d+);
$.($1*$2*
```
Handle `Pair` by taking the product of the values.
```
F(\d+)
F$1*
```
Convert the first parameter of `Func` to unary.
```
(F_*)_(,\d+;)
P$1$2$2
```
Compute `Func(n+1,m)` as `Func(n,m)*m` using `P` to do the multiplication.
```
F,\d+;
1
```
`Func(0,m)` is just `1`.
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 111 bytes
```
Op.{5}
EU,
T`NUB\O)(l`0-3;_
\d
$*
E(1*),(1*);
$1$2
(P1*)1(,1*;)
E$1$2$2
P,1*;
(F1*)1(,1*;)
P$1$2$2
}`F,1*;
1
1
```
[Try it online!](https://tio.run/##bY69CsIwFIX3@xwVbkoUozh1K7RuTQa7FUzRgIGSlhBdpM9em1jFUpfDPd@5f1Y5bephhXiUA@82z0MPWUnhJIsyrTjBRm7X@@QM1RWiGDJkMaFeEohYtAMUY82QsjghkHk0QuEtAOY/mZiyXuYhZcCGoVAPZaE02kHatg1wex19fjcXDBENSt7Et30A75xuTUBfE4bHJ7S7KYt@H/UyJ1OTqPUfsDhMA15spLOLhLwA "Retina 0.8.2 – Try It Online") Link includes reduced test cases, as Retina 0.8.2 has to calculate in unary, which limits the magnitude of the result. Explanation:
```
Op.{5}
EU,
```
Change `Option(` to `Either(Unit,` (except preabbreviated).
```
T`NUB\O)(l`0-3;_
```
Transliterate the `Never`, `Unit`, `Bool` and `Order` to `0` to `3` respectively, transliterate the `)` to `;` for ease of matching, and delete the lower case letters and `(`.
```
\d
$*
```
Convert to unary.
```
E(1*),(1*);
$1$2
```
Handle `Either` by taking the sum of the values.
```
(P1*)1(,1*;)
E$1$2$2
```
Compute `Pair(n+1,m)` as `Pair(n,m)+m` using `E` to do the addition.
```
P,1*;
```
`Pair(0,m)` is just `0`.
```
(F1*)1(,1*;)
P$1$2$2
```
Compute `Func(n+1,m)` as `Func(n,m)*m` using `P` to do the multiplication.
```
F,1*;
1
```
`Func(0,m)` is just `1`.
```
}`
```
Repeat the above transformations until the desired result is obtained.
```
1
```
Convert to decimal.
[Answer]
# JavaScript (ES7), 103 bytes
A regex-based solution. This is longer than using @hyper-neutrino's [method](https://codegolf.stackexchange.com/a/236251/58563), but not as much longer as I was expecting.
```
s=>eval(s.replace(/\w+/g,s=>(i="enorpiau".search(s[1]))<4?i:`((x,y)=>y${['|1+','+','*','**'][i&3]}x)`))
```
[Try it online!](https://tio.run/##pdJNT4MwGAfwu59iIUbarYJsvGxGZmKiR@fFE5KsYd1WQyhpGW7RfXak1YsdMVkh6XMA8uvTf593XGORcVpW1wVbkWYdNyKekxrnQDiclDnOCHDfPkbuBrUfAI0tUjBeUryzHEEwz7ZAJF4K4Z1/T2@XAOzRAcbzw@VnYn95IxvZcg3lGtppQq8m6XEPlxA2GSsEy4mTsw1YA@uZ1IRbEA5MH9cd3Fxo6GtBqz6mRD0dfWAs74uOdXTBV72PP9HRp12RARUsUhWeu0HX8RUqgzU0Oy9qUVaUFYqFRil0ZvqDqmiN1Bb1dfSRVlvCgRwCJItJpv@iRu22aKCjL5j2IRUadqInc4XU65No0J8bgKoDOVJh50ypon79bfiMvls1CsdBMIv8qT@bRs03 "JavaScript (Node.js) – Try It Online")
### How?
All keywords can be unambiguously identified by looking at the second character. Hence the lookup string `"enorpiau"` and an index `i` into this string. We use the pattern `((x,y)=>y…x)` for all operations.
```
 i | keyword  | translation
---+----------+----------------
 0 | N[**e**]ver  | 0
 1 | U[**n**]it   | 1
 2 | B[**o**]ol   | 2
 3 | O[**r**]der  | 3
 4 | O[**p**]tion | ((x,y)=>y|1+x)
 5 | E[**i**]ther | ((x,y)=>y+x)
 6 | P[**a**]ir   | ((x,y)=>y*x)
 7 | F[**u**]nc   | ((x,y)=>y**x)
```
[Answer]
# [Julia 1.0](http://julialang.org/), 87 bytes
```
eval∘Meta.parse
Never,Unit,Bool,Order=0:3
Option,Pair,Either=x->x+1,*,+
Func(x,y)=y^x
```
[Try it online!](https://tio.run/##bZHPTsMwDMbveQozcUhYNu1/N6TugAQSB9guXEHV6oqgKq1Sb@regEfg@XiR0jiVNhiVark/O46/rx/73CTjusniBg9J/v359YSUDMvEVSie8YBOv1hD@q4ocr1xKbp4dDsVm5JMYfU2MU7fG3pvcT1Y1/2xvtF98bC3O1nro4qPr3VDWFEFMVRlbmgoHSZpbixWUikhssKBJP2mUYGxwL0C2qd0xlJuJUG8hkxS2@yxyfgDrmLgHeWjpfYs186P9bAucUeYwjX2QhltKtq3YVUwWMNIeGk@Gwuvz2cTwSJ9Og06ggkcVehlzK6c6KizhLnqJgXCAxnNRPBKsps@/INP7XPh/f1LF4Fe7MY/Q15coH9toYKERdDAgQvd/LNrosVkPl9Fs@VstYx@AA "Julia 1.0 – Try It Online")
Same idea as the other answers
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~66~~ ~~61~~ 60 bytes
```
Ｆ⮌Ｓ«≡ιd⊞υ³B⊞υ²U⊞υ¹N⊞υ⁰p⊞υ⊕⊟υE⊞υ⁺⊟υ⊟υP⊞υ×⊟υ⊟υF«≔⊟υθ⊞υＸ⊟υθ»»Ｉυ
```
[Try it online!](https://tio.run/##fZDNigIxDIDP41MUTyl0YX9u60lFwYsWd/cBSic6hbGd7Y8eFp@9tsM6UzwIIZAvH2kT2QgrjWhjPBhLYI9ntA5ho7vgv7xV@giUUvI3qdxFedkQUH0lhUMyraefhAfXQGDkg87ueFHg9xH/FPhtxNsCv464K/BGS4sn1B5r4KaDkP40iKtC5G1w/0YqHk1emN/qhE/UdVLTmtXcOXXUg/ebjWp4zVzQFr3cvOa4Tng6nYelcD7PncXIhbKwDlrCNt@Y9ZmyHq@Ub9KghTEty4myXeeV0bCzdZIojS/n9gY "Charcoal – Try It Online") Link is to verbose version of code. Edit: Saved 5 bytes thanks to @KevinCruijssen pointing out that `d` and `p` uniquely identify `Order` and `Option`. Saved 1 byte by finding a slightly shorter way to exponentiate. Explanation:
```
Ｆ⮌Ｓ«
```
Loop over the characters of the input string in reverse order.
```
≡ι
```
Switch on the current character.
```
d⊞υ³
```
For `(Or)d(er)` push `3` to the predefined empty list.
```
B⊞υ²
```
For `B(ool)` push `2` to the predefined empty list.
```
U⊞υ¹
```
For `U(nit)` push `1` to the predefined empty list.
```
N⊞υ⁰
```
For `N(ull)` push `0` to the predefined empty list.
```
O⊞υ⊕⊟υ
```
For `(O)p(tion)` increment the top of the list.
```
E⊞υ⁺⊟υ⊟υ
```
For `E(ither)` sum the top two elements of the list.
```
P⊞υ×⊟υ⊟υ
```
For `P(air)` multiply the top two elements of the list.
```
F«≔⊟υθ⊞υＸ⊟υθ»
```
For `F(unc)` exponentiate the top two elements of the list. (Unfortunately the elements are in the wrong order, complicating the code. I tried processing the string from left to right which avoids that issue but that then requires an operator stack which ends up making the code much longer.)
```
»
```
Ignore any other characters.
```
Ｉυ
```
Output the final result.
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~120~~ 95 bytes
```
p=i=->x,y=1{x+y}
a=->x,y{x*y}
u=->x,y{y**x}
f=->s{eval s.gsub(/\w+/){$&[1]}.tr'enor()','0-3[]'}
```
[Try it online!](https://tio.run/##nZLJboMwEIbvPIWVVGWJE3ZIDuRQqT02ufSU5kBS0iIhQCwpCPnZKdiWTNgOvVjMP/98M2OT5JeyrmPHd9b7ApaOWhWrEnEuCatCaoKcBqUkFYi7NVFaeXc3AOnmO80vgvz5u5LF6un5pJ7RJkt4L4wSQeQhr6z105lHdZxnqbB49@5eApw9WFbgtrm6QUC1hQgQkOVGV1DzvQQKRyo@Qj/rFbQS86vEr1L/SxQFPX8rMb9G/Br1H5KvwURYYxU6qdBpxVseXgU8NMSn2Kse5Cdnxc52mxlQJz15R4c486MQW/uMbmr6DogJrz0BIDlGMAjBoIRXP/vxEqG9aTiKGRoYyyQsk7KOrj9H6qcZxyIcq8sZPAbEcnec9hDhw57iaNP/sjrvT0dUre4fgA9spiuNLz7rZT1sSzPNnW1sjd3WJu0eJK7@Aw "Ruby – Try It Online")
* Thanks to @Dingus for the 25 Bytes saved!
[Answer]
# [R](https://www.r-project.org/), 121 bytes
Or **[R](https://www.r-project.org/)>=4.1, 100 bytes** by replacing the three `function` appearances with `\`s.
```
function(s,Never=0,Unit=1,Bool=2,Order=3,Option=function(x)x+1,Either=`+`,Pair=`*`,Func=function(a,b)b^a)eval(parse(t=s))
```
[Try it online!](https://tio.run/##dZBPb8IwDMXvfArELvHwJFr6hxyyAxI7jl12nRpYqkVCbdUUxLcvsdt1i9guVf1@dt6z275UfXmujp2tK@Hw1VxMq1b4XtlORbit65OKcd9@enWN@4ba1NR/hesywp3tvjwulgW@aet/Hgt88S0/fRoPcPjQYC76JBrdOiM65QD6UizYcQEP86fn@WrmBbIe64hqyjDWMdUcZhTWJJCX4GeG@PB7miE9GTJ2GtZhCoHDoLPRN0gIDJsKSsSn@RcGoylRuswfLJvY3RZ8THFniUE6mJbNZjUDJ9zRNqZSUkqYLsAfHhn9wxh5FqepzJNNIjd5fwM "R – Try It Online")
[R](https://www.r-project.org/) doesn't have a simple `eval`, you need to `parse` the string first.
[Answer]
# [Haskell](https://www.haskell.org/), 206 bytes
```
f.read
data T=Never|Unit|Bool|Order|Option T|Either(T,T)|Pair(T,T)|Func(T,T)deriving Read
f(Option a)=f a+1
f(Either(a,b))=f a+f b
f(Pair(a,b))=f a*f b
f(Func(a,b))=f b^f a
f Never=0
f Unit=1
f Bool=2
f _=3
```
[Try it online!](https://tio.run/##PY9Nj8IgEIbv/oqJ8VCUNX6cuZisx3Vj6m2jmbZQyXZpQ7EnfrssTKuXycsD8@Tljv2vbJpQi5@g1lZiNavQIeTiSw7S@ovRzh/atvEnW8XzqXO6NZD7T@3u0mY5z5n/Rj2l48OUlOJbPWhTwzkpVTbtIRMKcLWNZBIgL9gIFRQRk@sNlyMk7QsW13gxU0AFxSamVFJEJ6SiYhfDTezDH2oDAjqrjYMF1DAnN7lol9NknPBUJxl4GoyPlTP6N2NsHp6larDuw0fZdf8 "Haskell – Try It Online")
[Answer]
# [Pari/GP](http://pari.math.u-bordeaux.fr/), 92 bytes
```
Never=0
Unit=1
Bool=2
Order=3
Option(x)=1+x
Either(x,y)=x+y
Pair(x,y)=x*y
Func(x,y)=y^x
eval
```
[Try it online!](https://tio.run/##K0gsytRNL/j/3y@1LLXI1oArNC@zxNaQyyk/P8fWiMu/KAUoaszlX1CSmZ@nUaFpa6hdweWaWZKRWqRRoVOpaVuhXckVkJgJ42lVcrmV5iVDeJVxFVypZYk5/wuKMvNKNEBMDSWwNJgAG64DJjWhlJKm5n8A "Pari/GP – Try It Online")
The same as [@hyper-neutrino's](https://codegolf.stackexchange.com/a/236251/9288) and [@wasif's](https://codegolf.stackexchange.com/a/236256/9288) answers.
[Answer]
# [Perl 5](https://www.perl.org/), 105 bytes
```
s/\w(.)\w+/$1/g;y/enor/0123/;1while s|([piau]).(\d+)(,(\d+))?\)|($4//1).({a,'*',u,'**'}->{$1}//'+').$2|ee
```
[Try it online!](https://tio.run/##bY5Bb4JAEIXv/AoPJLsjC9PF9kTSJk3qUXvxJB6IbuomhCULlBjxr3cLI5oQvbzJfPPmzZTK5m/OVZi2PIK0DdCX@JOcUBXG4ouMF5jI9qhzNas6vi111uwg4ukhAC6owEcKHfdfEWU/OGeCzZloep2zS/h@9uUFkQUMIj/ulHJupX6V9TaFrr1PY3JvbQ99v2yKPaeRIIUrGWw3sC5rbQpC94aWwfvS9VFZPuSJQaZkNH1n@gl4OCwIPySKyUUY/yMhNIaO5c@Qu3Jh@Q8 "Perl 5 – Try It Online")
]