Unresolved overloading - trying to make an instance for Int for own class










0















I have a class which pre-implements one function (by now) and I want to use it via Instances, I started with Int, which didnt work.
It compiles, but when i try to call the function with fac 3,
I get the following ERROR:



Unresolved overloading
* Type : Fibo a => a
*
Expression : fac 3



class (Eq a, Ord a, Show a, Num a) => Fibo a where
fac :: a -> a
fac n
| n == 0 = 1
| otherwise = n * fac (n-1)

instance Fibo Int where
fac n = fac n


I cannot understand why it isnt working for my class with Int when its working for Show with a new type like:



newtype IN_0 = IN_0 Int
instance Show IN_0 where
show (IN_0 n) = show n


At least i think that the misstake is in the instance part, I thought that all i need to do is removing the constructor and replacing the name...
Is something missing, can u tell me the difference of that what i did for show and why it didnt work for my own class?










share|improve this question




























    0















    I have a class which pre-implements one function (by now) and I want to use it via Instances, I started with Int, which didnt work.
    It compiles, but when i try to call the function with fac 3,
    I get the following ERROR:



    Unresolved overloading
    * Type : Fibo a => a
    *
    Expression : fac 3



    class (Eq a, Ord a, Show a, Num a) => Fibo a where
    fac :: a -> a
    fac n
    | n == 0 = 1
    | otherwise = n * fac (n-1)

    instance Fibo Int where
    fac n = fac n


    I cannot understand why it isnt working for my class with Int when its working for Show with a new type like:



    newtype IN_0 = IN_0 Int
    instance Show IN_0 where
    show (IN_0 n) = show n


    At least i think that the misstake is in the instance part, I thought that all i need to do is removing the constructor and replacing the name...
    Is something missing, can u tell me the difference of that what i did for show and why it didnt work for my own class?










    share|improve this question


























      0












      0








      0








      I have a class which pre-implements one function (by now) and I want to use it via Instances, I started with Int, which didnt work.
      It compiles, but when i try to call the function with fac 3,
      I get the following ERROR:



      Unresolved overloading
      * Type : Fibo a => a
      *
      Expression : fac 3



      class (Eq a, Ord a, Show a, Num a) => Fibo a where
      fac :: a -> a
      fac n
      | n == 0 = 1
      | otherwise = n * fac (n-1)

      instance Fibo Int where
      fac n = fac n


      I cannot understand why it isnt working for my class with Int when its working for Show with a new type like:



      newtype IN_0 = IN_0 Int
      instance Show IN_0 where
      show (IN_0 n) = show n


      At least i think that the misstake is in the instance part, I thought that all i need to do is removing the constructor and replacing the name...
      Is something missing, can u tell me the difference of that what i did for show and why it didnt work for my own class?










      share|improve this question
















      I have a class which pre-implements one function (by now) and I want to use it via Instances, I started with Int, which didnt work.
      It compiles, but when i try to call the function with fac 3,
      I get the following ERROR:



      Unresolved overloading
      * Type : Fibo a => a
      *
      Expression : fac 3



      class (Eq a, Ord a, Show a, Num a) => Fibo a where
      fac :: a -> a
      fac n
      | n == 0 = 1
      | otherwise = n * fac (n-1)

      instance Fibo Int where
      fac n = fac n


      I cannot understand why it isnt working for my class with Int when its working for Show with a new type like:



      newtype IN_0 = IN_0 Int
      instance Show IN_0 where
      show (IN_0 n) = show n


      At least i think that the misstake is in the instance part, I thought that all i need to do is removing the constructor and replacing the name...
      Is something missing, can u tell me the difference of that what i did for show and why it didnt work for my own class?







      haskell typeclass






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 3:22







      Lorem2979

















      asked Nov 15 '18 at 0:09









      Lorem2979Lorem2979

      84




      84






















          1 Answer
          1






          active

          oldest

          votes


















          0














          As far as I can see there are two problems.



          Firstly you need to write fac (3 :: Int) in order to disambiguate the type of 3. That will get you rid of the type error.



          Secondly you need to get rid of the line fac n = fac n in your instance definition. That results in an undefined method. Rather leaving the instance definition empty results in the default instance being used.






          share|improve this answer























          • Thank you for your fast answer, I removed the fac n = fac n line. But fac 3 was just a test, calling the function with the Value 3. When ever i wrote a function until now I could call it like that...

            – Lorem2979
            Nov 15 '18 at 1:28












          • Indeed I understand it is a test. Nonetheless my point was you should need write that call as fac (3::Int) instead to specify that the literal 3 is of type Int, rather than say an Integer.

            – Jorge Adriano
            Nov 15 '18 at 1:36











          • Thank you very much, I remember what (3::Int) means.

            – Lorem2979
            Nov 15 '18 at 1:41











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310646%2funresolved-overloading-trying-to-make-an-instance-for-int-for-own-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          As far as I can see there are two problems.



          Firstly you need to write fac (3 :: Int) in order to disambiguate the type of 3. That will get you rid of the type error.



          Secondly you need to get rid of the line fac n = fac n in your instance definition. That results in an undefined method. Rather leaving the instance definition empty results in the default instance being used.






          share|improve this answer























          • Thank you for your fast answer, I removed the fac n = fac n line. But fac 3 was just a test, calling the function with the Value 3. When ever i wrote a function until now I could call it like that...

            – Lorem2979
            Nov 15 '18 at 1:28












          • Indeed I understand it is a test. Nonetheless my point was you should need write that call as fac (3::Int) instead to specify that the literal 3 is of type Int, rather than say an Integer.

            – Jorge Adriano
            Nov 15 '18 at 1:36











          • Thank you very much, I remember what (3::Int) means.

            – Lorem2979
            Nov 15 '18 at 1:41
















          0














          As far as I can see there are two problems.



          Firstly you need to write fac (3 :: Int) in order to disambiguate the type of 3. That will get you rid of the type error.



          Secondly you need to get rid of the line fac n = fac n in your instance definition. That results in an undefined method. Rather leaving the instance definition empty results in the default instance being used.






          share|improve this answer























          • Thank you for your fast answer, I removed the fac n = fac n line. But fac 3 was just a test, calling the function with the Value 3. When ever i wrote a function until now I could call it like that...

            – Lorem2979
            Nov 15 '18 at 1:28












          • Indeed I understand it is a test. Nonetheless my point was you should need write that call as fac (3::Int) instead to specify that the literal 3 is of type Int, rather than say an Integer.

            – Jorge Adriano
            Nov 15 '18 at 1:36











          • Thank you very much, I remember what (3::Int) means.

            – Lorem2979
            Nov 15 '18 at 1:41














          0












          0








          0







          As far as I can see there are two problems.



          Firstly you need to write fac (3 :: Int) in order to disambiguate the type of 3. That will get you rid of the type error.



          Secondly you need to get rid of the line fac n = fac n in your instance definition. That results in an undefined method. Rather leaving the instance definition empty results in the default instance being used.






          share|improve this answer













          As far as I can see there are two problems.



          Firstly you need to write fac (3 :: Int) in order to disambiguate the type of 3. That will get you rid of the type error.



          Secondly you need to get rid of the line fac n = fac n in your instance definition. That results in an undefined method. Rather leaving the instance definition empty results in the default instance being used.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 1:05









          Jorge AdrianoJorge Adriano

          2,219919




          2,219919












          • Thank you for your fast answer, I removed the fac n = fac n line. But fac 3 was just a test, calling the function with the Value 3. When ever i wrote a function until now I could call it like that...

            – Lorem2979
            Nov 15 '18 at 1:28












          • Indeed I understand it is a test. Nonetheless my point was you should need write that call as fac (3::Int) instead to specify that the literal 3 is of type Int, rather than say an Integer.

            – Jorge Adriano
            Nov 15 '18 at 1:36











          • Thank you very much, I remember what (3::Int) means.

            – Lorem2979
            Nov 15 '18 at 1:41


















          • Thank you for your fast answer, I removed the fac n = fac n line. But fac 3 was just a test, calling the function with the Value 3. When ever i wrote a function until now I could call it like that...

            – Lorem2979
            Nov 15 '18 at 1:28












          • Indeed I understand it is a test. Nonetheless my point was you should need write that call as fac (3::Int) instead to specify that the literal 3 is of type Int, rather than say an Integer.

            – Jorge Adriano
            Nov 15 '18 at 1:36











          • Thank you very much, I remember what (3::Int) means.

            – Lorem2979
            Nov 15 '18 at 1:41

















          Thank you for your fast answer, I removed the fac n = fac n line. But fac 3 was just a test, calling the function with the Value 3. When ever i wrote a function until now I could call it like that...

          – Lorem2979
          Nov 15 '18 at 1:28






          Thank you for your fast answer, I removed the fac n = fac n line. But fac 3 was just a test, calling the function with the Value 3. When ever i wrote a function until now I could call it like that...

          – Lorem2979
          Nov 15 '18 at 1:28














          Indeed I understand it is a test. Nonetheless my point was you should need write that call as fac (3::Int) instead to specify that the literal 3 is of type Int, rather than say an Integer.

          – Jorge Adriano
          Nov 15 '18 at 1:36





          Indeed I understand it is a test. Nonetheless my point was you should need write that call as fac (3::Int) instead to specify that the literal 3 is of type Int, rather than say an Integer.

          – Jorge Adriano
          Nov 15 '18 at 1:36













          Thank you very much, I remember what (3::Int) means.

          – Lorem2979
          Nov 15 '18 at 1:41






          Thank you very much, I remember what (3::Int) means.

          – Lorem2979
          Nov 15 '18 at 1:41




















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310646%2funresolved-overloading-trying-to-make-an-instance-for-int-for-own-class%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo