Can the following type T
be defined formally in Haskell or another functional language?
Type T
contains functions that, given a collection (i.e., a set) of objects from X
, assign a number to each object in that collection.
For example, let's say we have a function t
from T
. Its argument arg
must be a collection (set) of objects from X
, for example a list of strings ['abc', 'def', 'xyz']. Its return value must be a function r
that takes only three possible arguments: 'abc'
, 'def'
or 'xyz'
, and returns a number. I particular don't want r
to accept just any string as an argument in this case.
An example might be "rank function", which, given a collection of objects, somehow assigns a rank to each of them. It doesn't return just a collection of numbers; rather it returns a function that takes any of the members of the original collection, and returns the rank of that member.
Of course, if I change my requirement a little, the things become super simple. I could ask that function t
simply takes a collection of objects and return a collection of numbers. This is almost, but not quite the same. Such a definition would require some additional work: I would have to match objects from the input collection to the objects in the output collection. And also it would not be as precise: potentially the returned collection of numbers may not match the input objects (e.g., there may be one number too many).
I would not be surprised if the constraint I'm describing is not expressible as a type constraint, and should be enforced in a different way.
EDIT: I was originally asking also to define a type U
which contains functions that take a function from X
into numbers, and returns a function of type T
. But I didn't explain this well, and it only adds confusion to my question. So it's better to ignore this part of my question.