Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

No instance for (RealFrac Note) arising from a use of ‘quantise’ #874

@jwaldmann

Description

@jwaldmann

[copied from https://club.tidalcycles.org/t/quantise-type/3684]

The quantise example fails because of a type error:

d1 $ s "superchip*8" # n (quantise 1 $ range (-10) (10) $ slow 8 $ cosine)
# release (quantise 5 $ slow 8 $ sine + 0.1)

No instance for (RealFrac Note) arising from a use of ‘quantise’

RealFrac is the type class that holds the round method that is used in quantize. Note is currently not an instance of RealFrac. Perhaps it should be? Especially in light of the comment (Note is Double)

class (Real a, Fractional a) => RealFrac a where
  round :: Integral b => a -> b

quantise :: (Functor f, RealFrac b) => b -> f b -> f b
quantise n = fmap ((/n) . (fromIntegral :: RealFrac b => Int -> b) . round . (*n))

one solution is to derive instance RealFrac Note, by extending this declaration

-- | Note is Double, but with a different parser
newtype Note = Note { unNote :: Double } 
  deriving (Typeable, Data, Generic, Eq, Ord, Enum, Num, 
    Fractional, Floating, Real)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions