Implement Resistor Colors exercise#808
Conversation
8d065e5 to
b5410fb
Compare
|
I keep getting this segmentation fault while running the PS: It runs fine on master, but fails on this branch. |
|
Since I couldn't find output containing segmentation fault in the Travis CI output, I am taking your word for it. Since I don't use configlet I regret being unable to assist in the specifics of that |
sshine
left a comment
There was a problem hiding this comment.
I think we need some kind of error handling built in.
I like this exercise over allergies for the reason that you don't need exponentiation, so it's less mathy.
If convert Black == 0, then what is value []? (This is perhaps a question better asked on problem-specifications.)
| convert Grey = 8 | ||
| convert White = 9 | ||
|
|
||
| value :: [String] -> Int |
There was a problem hiding this comment.
Since we're converting ["black", "brown"], I think it would make sense to
- Have error handling.
- Return an
Integer.
Since it makes sense to have error handling, it also makes sense to ask if we should go with Maybe or Either.
Then readMaybe or readEither from Text.Read can come into use.
There was a problem hiding this comment.
From the tests in specification, I assumed the input will always be valid. Let me know if I should make this change or wait for more discussion (in the problem spec as well).
That's strange, line 20 only contains
What if you It sounds like |
| deriving (Eq, Show, Read) | ||
|
|
||
| convert :: Color -> Int | ||
| convert Black = 0 |
There was a problem hiding this comment.
I notice that it would be possible to use http://hackage.haskell.org/package/base-4.12.0.0/docs/Prelude.html#t:Enum here.
I have not yet determined whether it would be a good idea to do so.
There was a problem hiding this comment.
I had the same thought.
What you don't get with deriving Enum is an explicit annotation that Black is 0, etc.
Making an explicit instance Enum where ... has the drawback that you need to specify both toEnum and fromEnum, even though the exercise only needs the one. There are ways to avoid that, but the first way (using a dynamic lookup table) should be discouraged, and the second way (using Data and Typeable) is probably a little too complicated to serve as a good example.
So I'm content with having a simple convert function.
|
I noticed that the Readme here is an older version of the Readme we actually implemented. |
|
@tejasbubane Can you regenerate the readme with (thanks/cc @ErikSchierboom ) |
|
Oh, my mistake. That command should actually be: |
b9ad557 to
8c19291
Compare
|
Regarding the configlet segfault issue - Sorry that was my bad. I had an old version (which was segfaulting) lying in my $PATH and that was picked up instead of bin/configlet: haskell/bin/ensure-readmes-are-updated.sh Lines 2 to 5 in 189f262 I have updated the README and the ensure script works fine now. |
8c19291 to
f8bb197
Compare
sshine
left a comment
There was a problem hiding this comment.
Travis CI reports a type error in the stub:
/home/travis/build/exercism/haskell/build/resistor-colors/stub/test/Tests.hs:20:29: error:
• Couldn't match type ‘Color’ with ‘[Char]’
Expected type: [String]
Actual type: [Color]
• In the first argument of ‘value’, namely ‘input’
In the first argument of ‘shouldBe’, namely ‘value input’
In the expression: value input `shouldBe` expected
|
20 | assertion = value input `shouldBe` expected
| ^^^^^
Other than that, I have no further comments before hitting approve.
f8bb197 to
1e7fc58
Compare
resistor-color-duo was added in #808. resistor-color-trio was added in #869. Yet there is no resistor-color. I argue that there shouldn't be. A reasonable solution might look like ```haskell data Color = ... deriving (Eq, Enum, Bounded) colorCode :: Color -> Int colorCode = fromEnum colors :: [Color] colors = [minBound..] ``` which makes it approximately as simple as the gigasecond exercise which was marked as deprecated in #280 (decision made in #230). Still, if it is simply missing, it will appear as an exercise that is potentially implementable on https://tracks.exercism.io/haskell/master/unimplemented Since a question was raised about this exercise once, marking it as foregone will limit further requests made in vain.
Problem Specification: exercism/problem-specifications#1466