Thanks for the ideas, but neither is satisfactory for my (crazy and contrived) use case :-)
@Maxime:
Once again, I maybe missing something, but
Basic.toString is not the only function that does that. My particular aim was to combine native functions and functions that simply ignore the parameter which are both examples of functions that can accept anything.
Also, more broadly you could have definitions such as:
type alias Mapper a =
{ map : List b -> (b -> a) -> List a
}
now - due to the erasing implementation of Elm, I can execute the
map function safely for any type of input as long as the first two parameters match. Now this latter case would require the compiler to infer things like
m : Mapper Int
x = m.map ["a" "b"]
--x: (String -> Int) -> List Int
Which may and may not be the exact same thing the compiler already does for regular functions.
There might even be a non-crazy use case for that :-)
@Nick:
I am aware of that possiblity, but adding type variables is not an option in my use case. I need to be able to call things like (highly contrived for brevity),
func: Convertor a -> Int -> String -> (a,a)
func conv i s =
(conv.convert i, conv.convert s)
which I could not do if I bind the type variable outside the individual subexpressions.
In case you are wondering why would I want such madness, I was toying with the idea of having automatic serialization/deserialization (JSON/XML etc.) of arbitrary non-function types (records and possibly also union types) in almost pure Elm, with only a single magic native function. The idea was like that:
--pure Elm type
type TypeInfo a = ...
--JavaScript magic
getTypeInfo: a -> TypeInfo a
--pure Elm
decoder: TypeInfo a -> Json.Decode.Decoder a
However, I ended up requiring the functions of the aforementioned weird form in
TypeInfo a so it probably cannot work. I am aware of cases that could not be solved in principle without help from compiler even if everything worked as I hoped it would (and maybe there are other problems I missed), but I had fun trying :-)
Still curious, if this idea could work in general or if it implies some problems for the whole type system...
Thanks
Martin