Jan*_*Jan 24
在Haskell你不转换到,但是从.见fromRational.
threeHalves :: Ratio Integer
threeHalves = 3 % 2
sqrt threeHalves -- Fails
sqrt $ fromRational threeHalves -- Succeeds
Run Code Online (Sandbox Code Playgroud)
如果需要某个Rational -> Float功能,可以将其定义为
toFloat x = fromRational x :: Float
Run Code Online (Sandbox Code Playgroud)