小编Ben*_*daj的帖子

多态常量可以映射到*类型*列表上吗?

Haskell 爱好者 - 是否可以以通用方式将多态常量映射到类型列表上?

\n

更准确地说,考虑这个片段:

\n
{-# LANGUAGE AllowAmbiguousTypes #-}\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE KindSignatures #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TypeApplications #-}\n{-# LANGUAGE TypeOperators #-}\n  \nmodule Main where\n\nimport Data.Kind( Type )\n\nclass HasName a where name :: String\n\ninstance HasName Int where name = "Int"\n\ninstance HasName Double where name = "Double"\n\n\nclass AllNames (ts :: [Type]) where\n  allNames :: [String]\n\ninstance AllNames '[] where\n  allNames = []\n\ninstance (HasName t, AllNames rest) => AllNames (t ': rest) where\n  allNames = name …
Run Code Online (Sandbox Code Playgroud)

haskell typeclass

8
推荐指数
1
解决办法
192
查看次数

标签 统计

haskell ×1

typeclass ×1