reset password
Author Message
ejaan
Posts: 27
Posted 22:06 Oct 15, 2016 |

Hello, 

 

Down is useful because the function compare recognizes things wrapped in Down and reverses the usual order of comparison. 

What does that mean! I did not get the idea behind the Down type! I google it too but not clear results !

Can I have a more clear explanation for it, please? 

In the following giving examples:

compare (Down x) (Down y) = compare y x
> sortBy (comparing Down) [4, -2, -7, 5]
[5,4,-2,-7]
-- That’s the same as
> sortBy (\a b -> compare (Down a) (Down b)) [4, -2, -7, 5] [5,4,-2,-7]
-- Which is the same as
> sortBy (\a b -> compare b a) [4, -2, -7, 5]
[5,4,-2,-7] 

Since the all the three functions are the same !!

Then, we need to use the Down type?

 

Thank you 

Eman

rabbott
Posts: 1649
Posted 00:04 Oct 16, 2016 |

I'll talk about it in class Monday.

ejaan
Posts: 27
Posted 00:20 Oct 16, 2016 |

Great looking forward to learning about that.

 

Thank you, professor Abbott

Last edited by ejaan at 00:20 Oct 16, 2016.