{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE NoFieldSelectors #-}
type Time = Rational
newtype Note = Note Double
deriving (Eq, Ord, Read, Show, Enum, Num, Fractional, Real, RealFrac, Floating, RealFloat)
data Pattern a = Pattern {query :: () -> [Maybe a]}
deriving (Functor)
data Pat a where
PNote :: Pat Note
PDouble :: Pat Double
PStr :: Pat String
PInt :: Pat Int
PTime :: Pat Time
PBool :: Pat Bool
data MondoPat a b = MondoPat
{ pat :: Pat a
, patToControl :: Pattern a -> Pattern b
}
fromInt :: MondoPat a b -> Maybe (Pattern Int -> Pattern b)
fromInt mpat = case mpat.pat of
PNote -> Just (mpat.patToControl . fmap fromIntegral)
PInt -> Just mpat.patToControl
_ -> Nothing
ghci 9.12 accepts
mhs 0.15.5 says cannot satisfy Num a
(this example is derived from the tidal-mondo package)
{-# LANGUAGE DuplicateRecordFields #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE ImportQualifiedPost #-} {-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE NoFieldSelectors #-} type Time = Rational newtype Note = Note Double deriving (Eq, Ord, Read, Show, Enum, Num, Fractional, Real, RealFrac, Floating, RealFloat) data Pattern a = Pattern {query :: () -> [Maybe a]} deriving (Functor) data Pat a where PNote :: Pat Note PDouble :: Pat Double PStr :: Pat String PInt :: Pat Int PTime :: Pat Time PBool :: Pat Bool data MondoPat a b = MondoPat { pat :: Pat a , patToControl :: Pattern a -> Pattern b } fromInt :: MondoPat a b -> Maybe (Pattern Int -> Pattern b) fromInt mpat = case mpat.pat of PNote -> Just (mpat.patToControl . fmap fromIntegral) PInt -> Just mpat.patToControl _ -> Nothingghci 9.12 accepts
mhs 0.15.5 says cannot satisfy Num a
(this example is derived from the tidal-mondo package)