Skip to content

GADTs in record not propagating constraint #449

@claudeha

Description

@claudeha
{-# 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions