Personal tools

Talk:Blow your mind

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
m
(Polynomial signum and abs)
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==Could these be on their own page?==
 
 
Hi Johannes - Great stuff on your page. Have you thought about making it an actual page in the WIKI? You could then add <pre>[[Category:Idioms]]</pre> and more people would find it. [[User:BrettGiles|BrettGiles]] 16:19, 1 March 2006 (UTC)
 
 
 
==Name?==
 
==Name?==
   
 
Is there a better name for this page? &mdash;[[User:Ashley Y|Ashley Y]] 00:55, 2 March 2006 (UTC)
 
Is there a better name for this page? &mdash;[[User:Ashley Y|Ashley Y]] 00:55, 2 March 2006 (UTC)
   
i completely agree, the name pretty much sucks. but what i really wanted, was to compile a collection of "idioms" that would enlarge the readers perception of what is possible in Haskell and how to go about it. so, i'll have to find a name that reflects this plan. &mdash;--[[User:JohannesAhlmann|Johannes Ahlmann]] 14:13, 2 March 2006 (UTC)
+
i completely agree, the name pretty much sucks. but what i really wanted, was to compile a collection of "idioms" that would enlarge the readers perception of what is possible in Haskell and how to go about it. so, i'll have to find a name that reflects this plan. &mdash;--[[User:JohannesAhlmann|J. Ahlmann]] 14:13, 2 March 2006 (UTC)
  +
  +
== List / String Operations ==
  +
  +
Should this:
  +
  +
transpose . unfoldr (\a -> toMaybe (null a) (splitAt 2 a))
   
== Elegance before pyrotechnics ==
+
be this instead:
   
The polynomial algorithms are indeed mind-blowing, like the excess of Mardi Gras. They smuggle in subscripts, which (blessedly) Haskell usually banishes, disguised in a pyrotechnic display of abstraction, replication, concatenation, composition and enumeration.
+
transpose . unfoldr (\a -> toMaybe (not $ null a) (splitAt 2 a))
   
Gilles Kahn invented a much more docile and beautiful way to do these things with true Haskell elegance long before Haskell:
+
== Polynomial signum and abs ==
   
instance Num a => [a] where
+
A sensible option for signum and abs for polynomials (with coefficients from a field) would be
fs + [] = fs
 
[] + gs = gs
 
(f:fs) + (g:gs) = f+g : fs+gs
 
   
(f:fs) * (g:gs) = f*g : [f]*gs + fs*(g:gs)
+
* signum -> the leading coefficient
_ * _ = []
+
* abs -> the monic polynomial obtained by dividing by the leading coefficient
   
Unlike the mind-blowing version, this code works on infinite series as well as polynomials. &mdash;[[User:dougm:Doug McIlroy]] 20 December 2006
+
As with the abs and signum functions for Integer and for Data.Complex (when restricted to a subring whose intersection with the real numbers is just the integers), the result of this signum is then a unit (ie, a value x for which there exists a y such that xy = 1), and we have
   
As can be easily seen from the history, i didn't add the polynomial code and haven't reviewed it due to its "length". This is a wiki; make any changes you think improve the page. Much of my own stuff needs comments or is generally obscure. I'd love it if someone added/removed/altered a few examples to make this page more "user friendly" --[[User:JohannesAhlmann|Johannes Ahlmann]] 22:44, 20 December 2006 (UTC)
+
* signum a * abs a = a
  +
* abs 1 = signum 1 = 1
  +
* abs (any unit) = 1
  +
* abs a * abs b = abs (a * b)

Revision as of 21:52, 25 August 2012

1 Name?

Is there a better name for this page? —Ashley Y 00:55, 2 March 2006 (UTC)

i completely agree, the name pretty much sucks. but what i really wanted, was to compile a collection of "idioms" that would enlarge the readers perception of what is possible in Haskell and how to go about it. so, i'll have to find a name that reflects this plan. —--J. Ahlmann 14:13, 2 March 2006 (UTC)

2 List / String Operations

Should this:

transpose . unfoldr (\a -> toMaybe (null a) (splitAt 2 a))

be this instead:

transpose . unfoldr (\a -> toMaybe (not $ null a) (splitAt 2 a))

3 Polynomial signum and abs

A sensible option for signum and abs for polynomials (with coefficients from a field) would be

  • signum -> the leading coefficient
  • abs -> the monic polynomial obtained by dividing by the leading coefficient

As with the abs and signum functions for Integer and for Data.Complex (when restricted to a subring whose intersection with the real numbers is just the integers), the result of this signum is then a unit (ie, a value x for which there exists a y such that xy = 1), and we have

  • signum a * abs a = a
  • abs 1 = signum 1 = 1
  • abs (any unit) = 1
  • abs a * abs b = abs (a * b)