<div dir="ltr">I've got this example from the Internet<div><br></div><div><font face="monospace">import Data.List<br>import Data.Maybe<br><br>firstFactorOf x<br>    | m == Nothing = x<br>    | otherwise = fromJust m<br>    where m =(find p [2..x-1])<br>          p y = mod x y == 0<br></font></div><div><br></div><div>and this as a crude return the nth element of a list</div><div><br></div><div><font face="monospace">import Data.List<br>import Data.Maybe<br><br>-- myIndex :: [a] -> Int -> Maybe a<br>myIndex [] _ = Nothing<br>myIndex (x:xs) 0 = Just x<br>myIndex (x:xs) n = myIndex xs (n-1)</font><br></div><div><br></div><div>I would like the Just x in the second block to actually be <font face="monospace">fromJust x</font> as in the first block, i.e., I want a number returned, not a <font face="monospace">Just</font> typed object. I've tried changing <font face="monospace">Just x</font> to <font face="monospace">fromJust x</font> but get the error when I try to use it</div><div><br></div><div><font face="monospace">> myIndex [1,2,3,4,5] 3</font><br></div><div><br></div><div><font face="monospace">     * Non type-variable argument<br>:         in the constraint: Num (Maybe (Maybe a))<br>:       (Use FlexibleContexts to permit this)<br>:     * When checking the inferred type<br>:         it :: forall a. Num (Maybe (Maybe a)) => Maybe a</font><br></div><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">What am I missing here? Also, my type declaration seems to be wrong too, but I don't see why.</font></div><div><br></div><div>LB</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div>