使用无点表示法时如何强制执行类型

Ber*_*ian 8 haskell pointfree

您好如何在编写方法时强制执行GHC 类似函数Data.Text.read=~运算符的类型Text.Regex.Posix

例:
a=["1.22","3.33","5.55"]

没有点免费:
b= map (\x-> read x ::Double) a

如何read使用无点表示法强制执行类型?

b=map read::Double a
b= map (read . f1 .f2 .f3... . fn )::Double a (构成方法时)
,其中f1 , f2 ...fn一些方法

或者更好的是,read当它属于一系列方法时,如何指定类型,不是在链的末尾!:
b=map (f2 . read . f1 ) a

lef*_*out 11

现代Haskell的最佳方法是使用类型应用程序.

Prelude> :set -XTypeApplications 
Prelude> map (read @Double) ["1.22","3.33","5.55"]
[1.22,3.33,5.55]
Prelude> map (read @Int) ["1.22","3.33","5.55"]
[*** Exception: Prelude.read: no parse
Run Code Online (Sandbox Code Playgroud)

这有效,因为read有签名

read :: ? a . Read a => String -> a
Run Code Online (Sandbox Code Playgroud)

因此read @Double专门a ~ Double并且因此

read @Double :: String -> Double
Run Code Online (Sandbox Code Playgroud)