Question: I am new to react and struggling to change the state of a component, and on the change replace the contents.

I have the following:

```js
function App() {

 const [page, setPage] = React.useState('list');

 switch(page) {
  case 'A':
   return(
   <body> 
    <Home />
    <A />
   </body>
  )
  case 'B':
  return(
   <body> 
    <Home />
    <B />
   </body>
  )
 }
}

function A() {

 return (
  <div>
   <div onClick={() => setPage('B')}>GoToB</div>
  </div>
 )
}

function B() {
    return (
       <div>test</div>
    )
}

```

There is a separate `Home` component that displays properly. How do I correctly call the `setPage` function to change the state so that the switch case is triggered and changes out the component?

Answer: 
The `mod n 2 == 0` constraints `n` to be an [**`Integral`** type](https://hackage.haskell.org/package/base-4.15.0.0/docs/Prelude.html#t:Integral), but then you use `x/n` and since the `(/)` function has signature [**`(/) :: Fractional a => a -> a -> a`**](https://hackage.haskell.org/package/base-4.15.0.0/docs/Prelude.html#v:-47-), this means that `x` and `n` have the same [**`Fractional`** type](https://hackage.haskell.org/package/base-4.15.0.0/docs/Prelude.html#t:Fractional). It makes no sense that a number type is both `Integral` and `Fractional`.

You can work with `fromIntegral` to convert `n` to a `Fractional` type:

```
recursion :: (Integral a, Floating b) => a -> b -> b
recursion n x = if mod n 2 == 0 
                  then x/**fromIntegral** n + (recursion (n-1) x)**(-1) 
                  else **fromIntegral** n/x + (recursion (n-1) x)**(-1)
```

Another problem with your function is that there is no *stop condition*. You need to add an extra clause:

```
recursion :: (Integral a, Floating b) => a -> b -> b
recursion n x
  | **n <= 0 = 0**
  | mod n 2 == 0 = x/**fromIntegral** n + (recursion (n-1) x)**(-1) 
  | otherwise = **fromIntegral** n/x + (recursion (n-1) x)**(-1)
```

This then produces for example:

```
Prelude> recursion 10 2
0.3481658094621751

```
Probably not an answer but this one would correspond more closely to the caption:

```hs
tSumToN :: (Enum a, Fractional a) => Int -> a -> a
tSumToN n = sum . take n . tSeq

tSeq :: (Enum a, Fractional a) => a -> [a]
tSeq x = 
  interleave odds evens
  where
    odds = [ o / x | o <- [1,3..]]
    evens = [ x / e | e <- [2,4..]]
    interleave [] _ = []
    interleave (y:ys) zs = y:interleave zs ys

example :: Double
example = tSumToN 4 1.1

```

btw: this one does obviously not converge mathematically so it seems rather pointless to take partial sums - but hey whatever