Hi,<div><br></div><div>you can always check the types using GHCi prompt:</div><div><br></div><div><div>*Prelude> :i (,)</div><div>data (,) a b = (,) a b <span class="Apple-tab-span" style="white-space:pre">        </span>-- Defined in GHC.Tuple</div>
<div>instance (Bounded a, Bounded b) => Bounded (a, b)</div><div> -- Defined in GHC.Enum</div><div>instance (Eq a, Eq b) => Eq (a, b) -- Defined in Data.Tuple</div><div>instance Functor ((,) a) -- Defined in Control.Monad.Instances</div>
<div>instance (Ord a, Ord b) => Ord (a, b) -- Defined in Data.Tuple</div><div>instance (Read a, Read b) => Read (a, b) -- Defined in GHC.Read</div><div>instance (Show a, Show b) => Show (a, b) -- Defined in GHC.Show</div>
<div><br></div><div>that's for a tuple. You can see that tuple has an instance for the Ord class.</div><div><br></div><div>*Prelude> :i ()</div><div>data () = () <span class="Apple-tab-span" style="white-space:pre">        </span>-- Defined in GHC.Unit</div>
<div>instance Bounded () -- Defined in GHC.Enum</div><div>instance Enum () -- Defined in GHC.Enum</div><div>instance Eq () -- Defined in Data.Tuple</div><div>instance Ord () -- Defined in Data.Tuple</div><div>instance Read () -- Defined in GHC.Read</div>
<div>instance Show () -- Defined in GHC.Show</div><div><br></div><div>and that's for a unit type.</div><br><div class="gmail_quote">On 3 March 2011 08:09, Karthick Gururaj <span dir="ltr"><<a href="mailto:karthick.gururaj@gmail.com">karthick.gururaj@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello,<br>
<br>
I'm learning Haskell from the extremely well written (and well<br>
illustrated as well!) tutorial - <a href="http://learnyouahaskell.com/chapters" target="_blank">http://learnyouahaskell.com/chapters</a>.<br>
I have couple of questions from my readings so far.<br>
<br>
In "typeclasses - 101"<br>
(<a href="http://learnyouahaskell.com/types-and-typeclasses#typeclasses-101" target="_blank">http://learnyouahaskell.com/types-and-typeclasses#typeclasses-101</a>),<br>
there is a paragraph that reads:<br>
Enum members are sequentially ordered types - they can be enumerated.<br>
The main advantage of the Enum typeclass is that we can use its types<br>
in list ranges. They also have defined successors and predecesors,<br>
which you can get with the succ and pred functions. Types in this<br>
class: (), Bool, Char, Ordering, Int, Integer, Float and Double.<br>
<br>
What is the "()" type? Does it refer to a tuple? How can tuple be<br>
ordered, let alone be enum'd? I tried:<br>
Prelude> take 10 [(1,1) ..]<br>
<interactive>:1:8:<br>
No instance for (Enum (t, t1))<br>
arising from the arithmetic sequence `(1, 1) .. '<br>
at <interactive>:1:8-17<br>
Possible fix: add an instance declaration for (Enum (t, t1))<br>
In the second argument of `take', namely `[(1, 1) .. ]'<br>
In the expression: take 10 [(1, 1) .. ]<br>
In the definition of `it': it = take 10 [(1, 1) .. ]<br>
<br>
This is expected and is logical.<br>
<br>
But, surprise:<br>
Prelude> (1,1) > (1,2)<br>
False<br>
Prelude> (2,2) > (1,1)<br>
True<br>
Prelude> (1,2) > (2,1)<br>
False<br>
Prelude> (1,2) < (2,1)<br>
True<br>
<br>
So tuples are in "Ord" type class atleast. What is the ordering logic?<br>
<br>
Another question, on the curried functions - specifically for infix<br>
functions. Suppose I need a function that takes an argument and adds<br>
five to it. I can do:<br>
Prelude> let addFive = (+) 5<br>
Prelude> addFive 4<br>
9<br>
<br>
The paragraph: "Infix functions can also be partially applied by using<br>
sections. To section an infix function, simply surround it with<br>
parentheses and only supply a parameter on one side. That creates a<br>
function that takes one parameter and then applies it to the side<br>
that's missing an operand": describes a different syntax. I tried that<br>
as well:<br>
<br>
Prelude> let addFive' = (+5)<br>
Prelude> addFive' 3<br>
8<br>
<br>
Ok. Works. But on a non-commutative operation like division, we get:<br>
Prelude> let x = (/) 20.0<br>
Prelude> x 10<br>
2.0<br>
Prelude> let y = (/20.0)<br>
Prelude> y 10<br>
0.5<br>
<br>
So a curried infix operator fixes the first argument and a "sectioned<br>
infix" operator fixes the second argument?<br>
<br>
Regards,<br>
Karthick<br>
<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Regards, Paul Sujkov<br>
</div>