Out of sheer curiosity, I wonder if something like the following is possible in Haskell:
A function foo
takes another function as an argument that is called in the body of foo
more than once, changing the type of the arguments along the way.
This following code does not compile because fn
's argument's types are pinned down once it is called, but hopefully it illustrates what I'm babbling about.
main = putStrLn (foo id)
foo :: (* -> *) -> [Char] -- maybe I'm also getting the whole *-thing wrong
foo fn =
let
val1 = fn "hey"
val2 = fn 42
in
show (val1, val2)
I wonder if it can be achieved at all, and if you can do it without helpers like typeclasses.