-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ prelude ] Give every Show
type a default Interpolation
#2245
Conversation
Show a
type a default Interpolation a
`Show
type a default Interpolation
20718fd
to
2c9bf24
Compare
Thanks to @ohad for the suggestion, we're now resolving the ambiguity explicitly by runtime pattern matching on the type |
I'm not sure I'm comfortable merging this without good evidence it does not imply hanging onto |
I tried to codegen two samples into chez scheme, it seems that the type indeed get earased, but because I'm not familiar with scheme I'm not 100% sure about it. -- with runtime `a : Type`
main : IO ()
main = putStr (interpolate True)
-- w/o runtime `a : Type`
module Main
%hide interpDefault
Interpolation Bool where
interpolate = show
main : IO ()
main = putStr (interpolate True)
|
Sorry for chiming in here, but I'm not sure that this is really an improvement over the status quo. I think there was an agreement that Interpolation Foo where interpolate = show |
@stefan-hoeck In 99.99% of the cases, you won't add your own
According to @ohad's comment, the custom implementations on type coming with |
If this is true, why do we even need the Interpolation String where interpolate x = x and nothing else in the Prelude? |
I mean |
I'm not sure I understand this correctly. The
I agree that having to type
This also affords is the option to backpedal without making a breaking change if we find a solution to ambigious interfaces, what do you think? |
@andrevidela The users may also want to use the multiline version To me, the first reasonable solution to your example should be to add a Therefore, it leads to a design decision of Idris: How to idiomatically add more new format behavior to Idris? Currently, Idris only has two behavior I think functions are more flexible and idiomatic in Idris rather than builtin formatter, so I think we should use simple functions for new format behavior. Then the To give a concrete example on top of yours: record HTTPRequest where
method : String
uri: String
header : String
body : String
Show HTTPRequest where
show req = """
method: \{req.method}
uri: \{req.uri}
header: \{req.header}
body: \{req.body}
"""
display : HTTPRequest -> String
display req = "\{req.Method} \{req.uri}"
...
-- Use show to render Requests by themselves
sendRequest : HTTPRequest -> IO ()
sendRequest req = server.send (show req)
...
-- Use interpolate to insert in other strings
parseRequest : RequestParser a => Request -> Log a
parseRequest req = case parse req of Nothing => LOG Error "could not parse \{display req}"; Just v => pure v |
Once imported |
There more I read about this, the more this sounds like a code smell. Why do we have an Edit: And if this criticism sounds too harsh: Please understand, that I am very glad about your work on string interpolation and raw string literals. They are a really great and useful addition to the language. :-) |
@stefan-hoeck Yes! Exactly the same as my previous comment a long time ago. Anyway, I now believe a default |
Signed-off-by: andylokandy <andylokandy@hotmail.com>
I don't understand where this impression came from. Adding your own implementation is only a problem if we accept the idea of adding this |
The idea comes from this comment |
This impression comes from the discussion in this PR. Namely:
Agreed. |
Now every type implemented
Show
is allowed to be interpolated into strings without following ashow
.Previous discussion on #1967 (comment)