toUpper c = chr (fromIntegral (towupper (fromIntegral (ord c))))  
... 
foreign import ccall unsafe "u_towupper"
  towupper :: CInt -> CInt
Run Code Online (Sandbox Code Playgroud)
是什么意思chr,以及u_towupper?我对这foreign import ccall unsafe部分也很好奇.Haskell源实际上是否会发生变异,因此unsafe?
Twa*_*ven 11
首先ord将一Char到Int,然后fromIntegral将其转换为CInt.在另一侧fromIntegral将一CInt到Int,然后chr转换Int到一个Char.
一个unsafe外国进口意味着C函数u_towupper没有回调到哈斯克尔.如果Ghc知道这一点,那么它可以进行一些优化.它与变异无关.