Haskell提供
typed holes.
例:
f :: Int -> String -> Bool f x y = if (x > 10) then True else (g y) g :: String -> Bool g s = _
汇编:
Prelude> :l HoleEx.hs [1 of 1] Compiling Main ( HoleEx.hs,interpreted ) HoleEx.hs:6:7: Found hole `_' with type: Bool Relevant bindings include s :: String (bound at HoleEx.hs:6:3) g :: String -> Bool (bound at HoleEx.hs:6:1) In the expression: _ In an equation for `g': g s = _ Failed,modules loaded: none.
在Scala中编程时,我通常使用???作为我的Scala代码中的占位符,我还没写过.
但是,使用打字孔对我来说似乎更强大.请注意,我可以用else替换上面的其他(g y)(g 55),但是我得到一个编译时错误:
Prelude> :l HoleEx.hs [1 of 1] Compiling Main ( HoleEx.hs,interpreted ) HoleEx.hs:3:39: Couldn't match type `Int' with `[Char]' Expected type: String Actual type: Int In the first argument of `g',namely `x' In the expression: (g x) Failed,modules loaded: none.
虽然我可以使用???在Scala中获取占位符实现进行编译,与孔不同,我将使用???获取运行时错误.
scala> def g(x: Int): Int = ??? g: (x: Int)Int scala> g(5) scala.NotImplementedError: an implementation is missing
Scala是否有打孔?