Reputation
12,107
Top tag
Next privilege 15,000 Rep.
Protect questions
Badges
3 43 66
Newest
 Yearling
Impact
~182k people reached

2d
revised Haskell: Is it possible to convert a Num to a Float?
added 387 characters in body
2d
comment Haskell: Is it possible to convert a Num to a Float?
I do know of a reasonable way to do what you're asking, I just doubt you really need to do it. It's not really a good idea to be doing because it's not going to be compile time guaranteed, conversions generally aren't which is why they're notoriously absent from Haskell as a whole. It's generally better to figure out how to make the type information available to the compiler so conversion isn't necessary vs. just forcing the conversion at runtime when you don't have a guarantee that the instance will be convertible.
2d
answered Haskell: Is it possible to convert a Num to a Float?
2d
comment Haskell: Is it possible to convert a Num to a Float?
why don't you store them as a Float if you need Float ? Float is an instance of Num, you can definitely make any functions you use that do + have a Num type restriction, and they'll take in a Float and return a Float...
Aug
25
awarded  Yearling
Aug
12
comment Lines of code that take on too much responsibility
I hate the second; more code = less readable = less maintainable often times. Semantic density is something that needs to be balanced, your first example has too much meaning in a small space - it's too semantically dense, your second example is not dense enough; it takes too much reading to gain an insight into the semantic purpose of the code. It's intuitive to strike a balance of semantic density in english: You don't stretch a statement across as many words as possible, and you don't smush it into it's most compact form because neither is very understandable.
Jul
31
comment How to better define SRP and “wholesome” objects?
you misunderstand SRP - it doesn't mean that class is responsible for all of it's things. Quite the opposite. SRP means any given module is responsible for one and only one thing, not a collection of things.
Jul
27
comment Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
@Giorgio edited my answer - have another look, though it relies on Eq as well as Monoid - I really feel like I'm missing something where Monoid should give the ability to succeed fast by simple function application rather than requiring the extra Eq, but can't think of it off hand. Also there really probably is an implementation in the standard libraries, I just don't know of it off hand.. Alternative works for Maybe and, but it's functionality is unclear to me as it appears to do more after success for [] and other types
Jul
27
comment Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
This is clean and simple but fixed to Maybe... My solution is constrained by Eq, somehow I feel like we're both missing something available by way of Monoid generally...
Jul
27
revised Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
deleted 33 characters in body
Jul
27
revised Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
deleted 33 characters in body
Jul
27
revised Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
deleted 33 characters in body
Jul
27
comment Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
@jk in a list the typically expected monoid is list under concatenation, where [] is the identity element - therefore the behaviour the poster wants would involve the first non [] to be the return value
Jul
27
comment Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
@Giorgio look at my last 2 examples of f to see why associativity is a necessity.
Jul
27
comment Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
@Giorgio perhaps that's why <|> doesn't rely on monoid and I have this all mixed up? It relies on Alternative typeclass. To be certain - I'm looking at my own answer and realizing it's not quite right as [1,2] <|> [3] gives the unexpected [1,2,3] so everything about using the monoid type class to identify an identity is right - and the other key is associativity is necessary to get the expected behaviour, perhaps Alternative doesn't give the behaviour I thought off hand...
Jul
27
answered Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
Jul
27
comment Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
Yes it does - this is Alternative which is the symbol infix operator <|> and is defined in terms of a Monoid
Jul
27
comment Does it make sense to use “ys” instead of “ies” in identifiers to ease find-and-replace functionality?
I'm partial to wolfys over wolfies myself...
Jul
24
comment Does Akka obsolesce JMS/AMQP message brokers?
You mention Camel's infinite integration capabilities but it can't integrate with Nothing. There needs to be something for it to integrate with, otherwise you're just enjoying the support for a bunch of services that you aren't running. Kick up JMS, or an HTTP or FTP server or something if you want to use Camel to integrate with something. Otherwise it's just blissfully providing infinite integration capabilities while integrating with nothing.
Jul
12
comment Is there a name for this pattern?
In the years I've been writing code, I haven't really bumped into this approach, and frankly I'm pleased with that- I would quickly change this if I saw it. This is frankly far too dangerous, without benefit (saves a single line of code..), and more importantly breaks the fluent reading of the code. while (condition) is simply more clear in it's intent than what you have there. Just don't do it, and your question becomes moot. No it doesn't have a name, for it is not common, and there's good reason.