<div dir="ltr">Got it to work this way but it got the wrong one. Still looking.<div><br></div><div><div><font face="monospace, monospace">instance Indexable (Tuple2 a) where</font></div><div><font face="monospace, monospace"> first (Tuple2 b a) = a</font></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 24, 2016 at 11:39 PM, Daniel Hinojosa <span dir="ltr"><<a href="mailto:dhinojosa@evolutionnext.com" target="_blank">dhinojosa@evolutionnext.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Quick adjustment, playing around too much with it, that should be:<div><br></div><div><div><font face="monospace, monospace">class Indexable idx where</font></div><div><font face="monospace, monospace"> first :: idx a -> a</font></div><div><br></div></div><div>Problem still exists.</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 24, 2016 at 11:25 PM, Daniel Hinojosa <span dir="ltr"><<a href="mailto:dhinojosa@evolutionnext.com" target="_blank">dhinojosa@evolutionnext.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I am pretty sure I have a good handle on type classes, but this one is perplexing me in Haskell. I created custom Tuples called Tuple2 and Tuple3 (I know Haskell already has Tuples, just thought I would create my own for this exercise). Then I wanted to create a type class that would have a method called first that would get the first element of the tuple regardless of what kind of Tuple it is. Tuple2, Tuple3, etc.<div><br></div><div>Here is what I have:</div><div><div><br></div><div><font face="monospace, monospace">data Tuple3 a b c = Tuple3 a b c deriving (Show)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">data Tuple2 a b = Tuple2 a b deriving (Show)</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">class Indexable idx where</font></div><div><font face="monospace, monospace"> first :: idx c -> a</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">instance Indexable (Tuple2 a) where</font></div><div><font face="monospace, monospace"> first (Tuple2 a b) = a</font></div><div><br></div></div><div>In my main, I try to get call <font face="monospace, monospace">putStrLn $ show $ first $ Tuple2 1 "One"</font></div><div><br></div><div>I was greeted with the following trace:</div><div><div><font face="monospace, monospace"> Couldn't match expected type ‘a1’ with actual type ‘a’</font></div><div><font face="monospace, monospace"> ‘a’ is a rigid type variable bound by</font></div><div><font face="monospace, monospace"> the instance declaration at TypeClasses.hs:35:10</font></div><div><font face="monospace, monospace"> ‘a1’ is a rigid type variable bound by</font></div><div><font face="monospace, monospace"> the type signature for first :: Tuple2 a c -> a1</font></div><div><font face="monospace, monospace"> at TypeClasses.hs:36:4</font></div><div><font face="monospace, monospace"> Relevant bindings include</font></div><div><font face="monospace, monospace"> a :: a (bound at TypeClasses.hs:36:18)</font></div><div><font face="monospace, monospace"> first :: Tuple2 a c -> a1 (bound at TypeClasses.hs:36:4)</font></div><div><font face="monospace, monospace"> In the expression: a</font></div><div><font face="monospace, monospace"> In an equation for ‘first’: first (Tuple2 a b) = a</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="arial, helvetica, sans-serif">Help is appreciated.</font></div><div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>