
Hello, I'm trying to practice my Haskell. So I had the idea of making a program which, given a mother's and a child blood type, it can determine whether a certain father is possible or not. Please take a look on this gist with my implementation: https://gist.github.com/aflag/14429dfb2e89791a44e2#file-parentaltesting Would you care to comment on it? It looks a bit cumbersome to my eyes. I'm trying to find the most intuitive and elegant way of do it. I'm not so much worried with performance. []'s Rafael

On Sat, Jun 28, 2014 at 11:16:31PM -0300, Rafael Almeida wrote:
I'm trying to practice my Haskell. So I had the idea of making a program which, given a mother's and a child blood type, it can determine whether a certain father is possible or not.
Please take a look on this gist with my implementation:
https://gist.github.com/aflag/14429dfb2e89791a44e2#file-parentaltesting
Would you care to comment on it? It looks a bit cumbersome to my eyes. I'm trying to find the most intuitive and elegant way of do it. I'm not so much worried with performance.
Since your 'main' function returns a Bool (possible/impossible), a simpler way to approach the problem is to calculate the potential blood-type of child C given parents A and B and then check the actual blood-type passed against this list (I attach a .hs with such solution). The 'cumbersome' part is the |Genes -> BloodType| conversion (and vice-versa); you can calculate the inverse instead of typing it out, but it will still be cumbersome.

Good idea. Attached is the best solution I could think of. I think it reads
quite elegantly :)
On Sun, Jun 29, 2014 at 2:05 AM, Francesco Ariis
On Sat, Jun 28, 2014 at 11:16:31PM -0300, Rafael Almeida wrote:
I'm trying to practice my Haskell. So I had the idea of making a program which, given a mother's and a child blood type, it can determine whether a certain father is possible or not.
Please take a look on this gist with my implementation:
https://gist.github.com/aflag/14429dfb2e89791a44e2#file-parentaltesting
Would you care to comment on it? It looks a bit cumbersome to my eyes.
I'm
trying to find the most intuitive and elegant way of do it. I'm not so much worried with performance.
Since your 'main' function returns a Bool (possible/impossible), a simpler way to approach the problem is to calculate the potential blood-type of child C given parents A and B and then check the actual blood-type passed against this list (I attach a .hs with such solution).
The 'cumbersome' part is the |Genes -> BloodType| conversion (and vice-versa); you can calculate the inverse instead of typing it out, but it will still be cumbersome.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

One thing I would suggest, as far as "Haskell style", is to make even short
programs like these into libraries. You don't need to write a main
function to test or even run such a simple program, and if you write it as
a library, you can re-use it.
On Sun, Jun 29, 2014 at 12:15 AM, Rafael Almeida
Good idea. Attached is the best solution I could think of. I think it reads quite elegantly :)
On Sun, Jun 29, 2014 at 2:05 AM, Francesco Ariis
wrote: On Sat, Jun 28, 2014 at 11:16:31PM -0300, Rafael Almeida wrote:
I'm trying to practice my Haskell. So I had the idea of making a program which, given a mother's and a child blood type, it can determine whether a certain father is possible or not.
Please take a look on this gist with my implementation:
https://gist.github.com/aflag/14429dfb2e89791a44e2#file-parentaltesting
Would you care to comment on it? It looks a bit cumbersome to my eyes.
I'm
trying to find the most intuitive and elegant way of do it. I'm not so much worried with performance.
Since your 'main' function returns a Bool (possible/impossible), a simpler way to approach the problem is to calculate the potential blood-type of child C given parents A and B and then check the actual blood-type passed against this list (I attach a .hs with such solution).
The 'cumbersome' part is the |Genes -> BloodType| conversion (and vice-versa); you can calculate the inverse instead of typing it out, but it will still be cumbersome.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

To solve the specific problem you pose, one doesn't need to know anything
about the relationship between alleles and blood types -- you don't even
need to know what an allele is :-)
If I didn't need to do anything else than just calculate whether a given
father's blood type is 'viable', I'd rather go for something like the
solution in attachment. I took advantage of this handy calculator
http://www.endmemo.com/medical/bloodtype.php while writing it.
Cheers,
On Sun, Jun 29, 2014 at 4:16 AM, Rafael Almeida
Hello,
I'm trying to practice my Haskell. So I had the idea of making a program which, given a mother's and a child blood type, it can determine whether a certain father is possible or not.
Please take a look on this gist with my implementation:
https://gist.github.com/aflag/14429dfb2e89791a44e2#file-parentaltesting
Would you care to comment on it? It looks a bit cumbersome to my eyes. I'm trying to find the most intuitive and elegant way of do it. I'm not so much worried with performance.
[]'s Rafael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- José A. Romero L. escherdragon@gmail.com "We who cut mere stones must always be envisioning cathedrals." (Quarry worker's creed)

On Sun, Jun 29, 2014 at 08:42:02PM +0200, José A. Romero L. wrote:
To solve the specific problem you pose, one doesn't need to know anything about the relationship between alleles and blood types -- you don't even need to know what an allele is :-)
Cleverly written (especially the last line of (#)! Though as it is: λ> (A # A) hangs -F

:-) Of course, if I were really serious about it I'd have written at least
one quickCheck test, right? Fixed version in attachment.
Cheers,
On Sun, Jun 29, 2014 at 9:10 PM, Francesco Ariis
On Sun, Jun 29, 2014 at 08:42:02PM +0200, José A. Romero L. wrote:
To solve the specific problem you pose, one doesn't need to know anything about the relationship between alleles and blood types -- you don't even need to know what an allele is :-)
Cleverly written (especially the last line of (#)! Though as it is:
λ> (A # A)
hangs -F _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- José A. Romero L. escherdragon@gmail.com "We who cut mere stones must always be envisioning cathedrals." (Quarry worker's creed)
participants (4)
-
Alexander Solla
-
Francesco Ariis
-
José A. Romero L.
-
Rafael Almeida