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

Add some useful interfaces to the core and std libs #1439

Closed
marijnh opened this issue Jan 5, 2012 · 11 comments
Closed

Add some useful interfaces to the core and std libs #1439

marijnh opened this issue Jan 5, 2012 · 11 comments

Comments

@marijnh
Copy link
Contributor

marijnh commented Jan 5, 2012

To find out whether they work well, we should try to actually use them. to_str and seq are some obvious candidates.

If #1438 is resolved, we can provide a core::impl::common module that exports impls for common interfaces of built-in types, so you'd only need a single import impl::common::* to get access to [1].len() and 10.to_str().

@kud1ing
Copy link

kud1ing commented Jan 5, 2012

Would it be possible to do this re-exporting in libcore/core.rs?

@marijnh
Copy link
Contributor Author

marijnh commented Jan 5, 2012

I think I'd rather not put a bunch of non-optional interfaces in every scope.

@kud1ing
Copy link

kud1ing commented Jan 5, 2012

Fair enough. I don't find it easy to map Haskell concepts to Rust all the time.

May i suggest that we consider that the interfaces are adjectives where possible?

@marijnh
Copy link
Contributor Author

marijnh commented Jan 5, 2012

Adjectives? Don't nouns (seq) or verbs (show) make more sense? Can you give some examples?

@kud1ing
Copy link

kud1ing commented Jan 5, 2012

Haskell is using adjectives for newer type classes, e.g. "IsString", "Foldable", "Traversable", "Typeable", "Storable"

I think TypeState predicates in Rust are mostly adjectives like "is_not_empty" etc.
Type classes are a similar requirement, but on the type.

My suggestion would be:

  • "to_str" => "is_showable"
  • "seq" => "is_iterable"

It's certainly a matter of taste:

fn foo<T: is_showable>(v: T) -> str
fn any<T: is_iterable>(v: T, f: block(U) -> bool) -> bool

which to me would be as nice as

 fn foo<T>(v: [T]) : is_not_empty(v) -> T

Why do nouns make more sense in your opinion?

@boggle
Copy link
Contributor

boggle commented Jan 5, 2012

I'd reserve adjectives for predicates and find some other naming scheme for interfaces. In any case, please do not use "is_", we just agreed to use that for predicates. I like marijns suggestion to try and use verbs for interfaces ("t: shows, t: iterates")

@graydon
Copy link
Contributor

graydon commented Jan 5, 2012

I agree interfaces are at least as likely verb-y as noun-y. But the -able and even -s suffixes seem noisy. The syntactic context makes it quite clear we're talking about an interface.

fn foo<T: fold iterate write>(...) 

looks ok to me.

@kud1ing
Copy link

kud1ing commented Jan 6, 2012

I'm fine with verbs. I've update the yet sketchy Core styleguide

@kud1ing
Copy link

kud1ing commented Jan 27, 2012

Was Stop passing spans to middle::trans functions that don't need them really meant to close Add some useful interfaces to the core and std libs?

@marijnh marijnh reopened this Jan 27, 2012
@marijnh
Copy link
Contributor Author

marijnh commented Jan 27, 2012

No! I got the bug number wrong.

@marijnh marijnh reopened this Mar 27, 2012
@marijnh
Copy link
Contributor Author

marijnh commented Mar 28, 2012

to_str is in, the seq stuff can be considered superseded by #1649

@marijnh marijnh closed this as completed Mar 28, 2012
@marijnh marijnh removed their assignment Jun 16, 2014
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
* fix incorrect #[note] syntax

* more syntax fixes

* add missing lifetime
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
* fix incorrect #[note] syntax

* more syntax fixes

* add missing lifetime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants