# How to convert (or cast) a pattern of Int to a pattern of Double

Haskell question: is it possible to cast a pattern of Int to a pattern of Double? Is there a nifty Tidal way to cast it?

Specifically, I want to cast a pattern produced by `markovPat` so that it can be used as the first argument in `select`:

``````let pat1 = "{1@3}%16"
pat2 = "1(3,8)"
pat3 = "1*8"
mpat = markovPat 8 1 [[3,5,2], [4,4,7], [2,1,3]]

d1 \$ struct (select (mpat / 2) [pat1, pat2, pat3]) \$ s "bd"
``````

The above code results in the error:

``````<interactive>:390:22: error:
• Couldn't match type ‘Int’ with ‘Double’
Expected: Pattern Double
Actual: Pattern Int
• In the first argument of ‘(/)’, namely ‘mpat’
In the first argument of ‘select’, namely ‘(mpat / 2)’
In the first argument of ‘struct’, namely
‘(select (mpat / 2) [pat1, pat2, pat3])’
``````

If I use `squeeze` without the `/ 2` instead of using `select`, the idea works, but I would really prefer to use `select` instead.

Ideas?

Ah, `fmap` solves my issue, and is even better because then I can create my own mapping:

``````let pat1 = "{1@3}%16"
pat2 = "1(3,8)"
pat3 = "1*8"
mpat = (fmap ([0,0.5,1]!!)) \$ markovPat 8 1 [[3,5,2], [4,4,7], [2,1,3]]

d1 \$ struct (select mpat [pat1, pat2, pat3]) \$ s "bd"
``````
1 Like

Chiming in just for reference: `fromIntegral :: (Integral a, Num b) => a -> b` can almost always get you where you need to go, ala `fromIntegral <\$> pat`.

1 Like