Oh snap, the simplify looks crazy! It would be so cool if you could make a post explaining how each little piece works in many details, once you are finished.
sortOn snd poly
poly is a list of tuples of two numbers for each polynomial term's coefficient and power. First step sorts the list of tuple by its second element which is power.
groupBy ...
We group all terms by their power. groupBy returns a list of lists. Each list represent a power value.
map f
For each list of lists we foldl the list which is basically reducing the list to a single value. For instance if we have 5x^2-3x^2+x^2 it evaluates to 3x^2.
Once you get used to functional programming, most things will look very clear. ;)
Take a look: http://learnyouahaskell.com
Oh snap, the simplify looks crazy! It would be so cool if you could make a post explaining how each little piece works in many details, once you are finished.
There are basically three transformations.
sortOn snd poly
poly is a list of tuples of two numbers for each polynomial term's coefficient and power. First step sorts the list of tuple by its second element which is power.
groupBy ...
We group all terms by their power.
groupBy
returns a list of lists. Each list represent a power value.map f
For each list of lists we
foldl
the list which is basically reducing the list to a single value. For instance if we have5x^2-3x^2+x^2
it evaluates to3x^2
.Once you get used to functional programming, most things will look very clear. ;)
Take a look: http://learnyouahaskell.com
I would agree.
meep
beep loves coding ? :D
meep