sorawee
2020-9-19 12:13:09

@notjack would be nice if we can invoke the pattern f^{–1} g f easily from your converter.

Like, (compose1 number->string add1 string->number)


notjack
2020-9-19 22:45:22

@sorawee what sort of use cases do you have for it?


sorawee
2020-9-19 22:46:27

This is the classic “change of basis” in algebra. And it’s useful in programming too as you can see in the above example


sorawee
2020-9-19 22:47:14

Like, I want to do some operations, but the data that I have right now can’t quite do that operation, so I need to convert it to a form that it can operates on, perform the operation, and then convert it back to the original format.


notjack
2020-9-19 23:06:59

in general I think if you’re finding yourself in that situation often enough that the utility would be super useful, that’s a symptom that something deeper is wrong and should be fixed - why isn’t the data in the right format to begin with?


notjack
2020-9-19 23:07:27

more importantly I’m not sure what a good name for such a utility would be


rokitna
2020-9-19 23:15:31

(convert-function-forward number<->string add1)

I think that makes it pretty readable; it converts a number-to-number function to a string-to-string function.


rokitna
2020-9-19 23:19:38

hmm


rokitna
2020-9-19 23:26:30
  (function<->function
    number<->string
    number<->string)
  add1)

With a function<->function conversion combinator like this, you can read off the left side (-> number? number?) and the right side (-> string? string?) of the conversion. It’s not as concise, but it’s easier to see how more complex type signatures would be catered to this way. [edited for code formatting]


notjack
2020-9-19 23:28:40

I think I’d rather just write (convert-backward number<->string (add1 (convert-forward number<->string x)))