Skip to content
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

Specialize trace to Text #230

Closed
srghma opened this issue Nov 10, 2019 · 5 comments
Closed

Specialize trace to Text #230

srghma opened this issue Nov 10, 2019 · 5 comments
Labels
question Further information is requested

Comments

@srghma
Copy link

srghma commented Nov 10, 2019

trace :: String -> a -> a
trace = Debug.trace

https://github.com/sdiehl/protolude/blob/7c0e45c844bedd311ecabf7c423039a98758a453/src/Debug.hs#L28-L32

@srghma srghma changed the title Specialize text to Text Specialize trace to Text Nov 10, 2019
@chshersh chshersh added the question Further information is requested label Nov 11, 2019
@chshersh
Copy link
Contributor

Hi, @srghma, we don't have the Print typeclass (as in your link from protolude) because one of our goals is to strive to have fewer custom abstractions. Another of our goals is to be beginner-friendly and have fewer surprises from Prelude and base when possible and when it doesn't conflict with other goals. We don't have a goal to replace each String with Text. However, we do have a goal to be performant. But trace is not used in production, it's a debugging-only function, so it's performance is not critical. That's why the type of the trace argument was chosen as String intentionally.

@srghma
Copy link
Author

srghma commented Nov 11, 2019

can we allow IsString ?

@chshersh
Copy link
Contributor

@srghma It's not possible to specify the type of the trace argument as IsString. Because IsString has only the following method:

fromString :: IsString s => String -> s

You will be able to pass to trace values of any type that implements IsString typeclass, but we won't be able to use it in the trace from base because it's not possible to implement the following function:

fromIsString :: IsString s => s -> String

@srghma
Copy link
Author

srghma commented Nov 12, 2019

didnt know

well, I could propose to use ToString class, but seems like you don't want and thus I see no reason to continue

@srghma srghma closed this as completed Nov 12, 2019
@chshersh
Copy link
Contributor

@srghma Yes, we have our own ToString, and it could work here. It's not that I don't want; there are just two incompatible solutions. With ToString it's more convenient to pass String or Text as an argument, but it's more challenging to work with polymorphic overloaded literals. So trace $ "Calling function foo with an argument: " <> show x will become a compile-time failure due to ambiguous type. So you either use explicit conversions in the case for monomorphic kinds (current behaviour), or you use explicit type annotations (proposed this issue). There's no win-win situation, and it's always about trade-offs. We just decided to choose the first option because for us it makes more sense, it's more convenient and beginner-friendly. Also, it's usually a good general rule I found beneficial when writing Haskell programs to follow the design approach to have polymorphic results instead of polymorphic arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants