我正在寻找将类型信息带入 Haskell 中的值级别的方法。
我知道将任何类型信息表示为值的一种方法是Language.Haskell.TH.Type. 有什么方法可以实现接受Proxy a并返回Language.Haskell.TH.Type类型(或表示任何类型的替代类型)的函数a,如下所示?
如果您有更好的想法将类型信息作为不使用的值Language.Haskell.TH.Type,也请告诉我。
import Data.Proxy (Proxy)
import Language.Haskell.TH (Type, TypeQ)
-- |
-- >>> amazing (Proxy :: Proxy Bool)
-- ConT GHC.Types.Bool
--
-- >>> amazing (Proxy :: Proxy [String])
-- AppT ListT (ConT GHC.Base.String)
amazing :: Proxy a -> Type
amazing p = undefined
-- |
-- Or if above is impossible, how about this?
amazingQ :: Proxy a -> TypeQ
amazingQ p = undefined
Run Code Online (Sandbox Code Playgroud) 我想a在函数中使用模糊类型如下,但它失败了.
foo :: (Read a, Show a) => IO ()
foo = print =<< (readLn :: IO a)
Run Code Online (Sandbox Code Playgroud)
目的是在实际调用时获得与给定类型签名不同的输出.
>>> foo :: Double => IO ()
34 -- user input
34.0 -- output
>>> foo :: Int => IO ()
34 -- user input
34 -- output
Run Code Online (Sandbox Code Playgroud)
我该怎么办呢?
我是Yesod的初学者,想要建立一个主要用静态文件构建的网站.
需要打开静态文件/,然后打开动态页面/foo.
所以我在static目录中准备了静态文件(例如,static/index.html,static/img/bar.gif,static/css/baz.css,...),并写成config/routes如下:
/ StaticR Static getStatic
/foo FooR GET POST
Run Code Online (Sandbox Code Playgroud)
Ghc声称
Exception when trying to run compile-time code:
Overlapping routes:
("StaticR","FooR")
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?