Haskell offers typed holes .
Example:
f :: Int -> String -> Bool
f x y = if (x > 10) then True else (g y)
g :: String -> Bool
g s = _
Compilation:
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.
When programming in Scala, I usually use ???placeholders in my Scala code that I haven't written yet.
However, using typed holes is more powerful for me. Note that I could replace the above else (g y)with else (g 55), but I would get a compile-time error:
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.
Although I can use ???Scala to compile placeholder implementers, unlike holes, I get runtime errors with ???.
scala> def g(x: Int): Int = ???
g: (x: Int)Int
scala> g(5)
scala.NotImplementedError: an implementation is missing
Does Scala have holes inserted?
source
share