隐式建造单身人士
我正在尝试隐式构建单例,然后将其传递到单身人士上的巫婆计算中。我想帮助GHC推断这种类型,但我还没有找到一种方法。
singletons [d| data Mood = Angry
| Sad
| Neutral
| Happy
| Excited deriving (Read, Eq, Ord, Show) |]
singletons [d| data Intensity = None
| Low
| Medium
| High
| Extreme deriving (Show, Read, Eq, Ord, Enum) |]
singletons [d| newtype MoodReport = MR (Mood, Intensity) deriving Show |]
moodReportToSing :: forall (a :: Mood) (b :: Intensity). (SingI a, SingI b) => MoodReport -> SMoodReport ('MR '(a,b))
moodReportToSing (MR (a,b)) = sing :: Sing ('MR '(a, b))
addSingMoodReports :: forall a a' (b :: Intensity) (c :: Intensity). SMoodReport ('MR '(a, b)) -> SMoodReport ('MR '(a, c)) -> SMoodReport ('MR '(a, b <> c))
addSingMoodReports (SMR (STuple2 a b)) (SMR (STuple2 a' c)) = SMR $ STuple2 a (b %<> c)
unsafeAddMoodReports :: MoodReport -> MoodReport -> MoodReport
unsafeAddMoodReports (MR (a, c)) (MR (b, d)) = MR (a, d <> c)
moodreeporttoming
仍然是明确的,需要打字才能使用。某种程度上的问题在于它会丢失类型数据(或者如果没有类型数据,我不知道如何使用该数据),并且其中只有友好的数据,我想将其传递给addsingmoodreports 功能。无论如何,是否可以隐含地将它们推断出GHC的类型或旁路类型搜索?
I'm trying to implicitly construct a singleton and then pass it into a function witch computes on singletons. I want to help GHC infer the type and I haven't figured out a way to do it.
singletons [d| data Mood = Angry
| Sad
| Neutral
| Happy
| Excited deriving (Read, Eq, Ord, Show) |]
singletons [d| data Intensity = None
| Low
| Medium
| High
| Extreme deriving (Show, Read, Eq, Ord, Enum) |]
singletons [d| newtype MoodReport = MR (Mood, Intensity) deriving Show |]
moodReportToSing :: forall (a :: Mood) (b :: Intensity). (SingI a, SingI b) => MoodReport -> SMoodReport ('MR '(a,b))
moodReportToSing (MR (a,b)) = sing :: Sing ('MR '(a, b))
addSingMoodReports :: forall a a' (b :: Intensity) (c :: Intensity). SMoodReport ('MR '(a, b)) -> SMoodReport ('MR '(a, c)) -> SMoodReport ('MR '(a, b <> c))
addSingMoodReports (SMR (STuple2 a b)) (SMR (STuple2 a' c)) = SMR $ STuple2 a (b %<> c)
unsafeAddMoodReports :: MoodReport -> MoodReport -> MoodReport
unsafeAddMoodReports (MR (a, c)) (MR (b, d)) = MR (a, d <> c)
the moodReportToSing
is still explicit and needs TypeApplications in order to to be used. The problem with SomeSing is that it loses type data (or if it doesn't, I don't know how to use that data) and only has kind data in it and I want to pass these to the addSingMoodReports
function. Is there anyway to make these implicitly, help GHC infer their type or bypass type-erasure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论