No instance for (Fractional [Double]) arising from the literal ‘1.0’Correct usage of the do notationPolyvariadic generalised sumFunction definition problems (No instance for … arising from)Haskell Location Definition “No instance for (Fractional Int) arising from a use of ‘/’”No instance for (Fractional ((Numerator, Denominator) -> Fraction a0 b0))Substitute n in [x|x<-[1..n]]No instance for (Integral Double) arising from a use of 'rem'Haskell No instance for (Fractional a0) arisingHow to convert from Int to Double?Haskell - No instance for (Eq (Int -> Int)) arising from a use of ‘==’

GPLv3 forces us to make code available, but to who?

Why do Russians sometimes spell "жирный" (fatty) as "жырный"?

Short story about a potato hotel that makes its guests into potatoes throughout the night

MaxCounters solution in C# from Codility

How to find places to store/land a private airplane?

Is there an in-universe explanation of how Frodo's arrival in Valinor was recorded in the Red Book?

Garage door sticks on a bolt

How do my husband and I get over our fear of having another difficult baby?

What does a textbook look like while you are writing it?

Giving a good fancy look to a simple table

IEEE 754 square root with Newton-Raphson

Is there a pattern for handling conflicting function parameters?

Should I be an author on another PhD student's paper if I went to their meetings and gave advice?

Could Boris Johnson face criminal charges for illegally proroguing Parliament?

What is The Difference Between Increasing Volume and Increasing Gain

What action is recommended if your accommodation refuses to let you leave without paying additional fees?

Did Tolkien ever write about a Heaven or Hell for Men?

Can Familiars read and use spell scrolls?

Probability of going broke

How is this situation not a checkmate?

Can I bring this power bank on board the aircraft?

How do we know neutrons have no charge?

How dangerous is a very out-of-true disc brake wheel?

Can anyone give me the reason why music is taught this way?



No instance for (Fractional [Double]) arising from the literal ‘1.0’


Correct usage of the do notationPolyvariadic generalised sumFunction definition problems (No instance for … arising from)Haskell Location Definition “No instance for (Fractional Int) arising from a use of ‘/’”No instance for (Fractional ((Numerator, Denominator) -> Fraction a0 b0))Substitute n in [x|x<-[1..n]]No instance for (Integral Double) arising from a use of 'rem'Haskell No instance for (Fractional a0) arisingHow to convert from Int to Double?Haskell - No instance for (Eq (Int -> Int)) arising from a use of ‘==’






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0















For class, we have to write some code for a given set of problems. One of these problems is to create an identity matrix in the form of a [[Double]] So far, I have come up with the following code. However, when I try to compile I get the following error, not sure of what I did wrong or what it means



CODE:



ident :: Int -> [[Double]]
ident x = identHelper x 0

identHelper :: Int -> Int -> [[Double]]
identHelper y z
| z == 0 = ([1.0] ++ replicate (y-1) 0.0) : identHelper y 1
| y == z = replicate (y-1) 0.0 : 1.0
| otherwise = (replicate z 0.0 ++ [1.0] ++ replicate (y-z-1) 0.0) : identHelper y (z+1)


ERROR:



 • No instance for (Fractional [[Double]])
arising from the literal ‘1.0’
• In the second argument of ‘(:)’, namely ‘1.0’
In the expression: replicate (y - 1) 0.0 : 1.0
In an equation for ‘identHelper’:
identHelper y z
| z == 0 = ([1.0] ++ replicate (y - 1) 0.0) : identHelper y 1
| y == z = replicate (y - 1) 0.0 : 1.0
| otherwise
= (replicate z 0.0 ++ [1.0] ++ replicate (y - z - 1) 0.0)
: identHelper y (z + 1)









share|improve this question
































    0















    For class, we have to write some code for a given set of problems. One of these problems is to create an identity matrix in the form of a [[Double]] So far, I have come up with the following code. However, when I try to compile I get the following error, not sure of what I did wrong or what it means



    CODE:



    ident :: Int -> [[Double]]
    ident x = identHelper x 0

    identHelper :: Int -> Int -> [[Double]]
    identHelper y z
    | z == 0 = ([1.0] ++ replicate (y-1) 0.0) : identHelper y 1
    | y == z = replicate (y-1) 0.0 : 1.0
    | otherwise = (replicate z 0.0 ++ [1.0] ++ replicate (y-z-1) 0.0) : identHelper y (z+1)


    ERROR:



     • No instance for (Fractional [[Double]])
    arising from the literal ‘1.0’
    • In the second argument of ‘(:)’, namely ‘1.0’
    In the expression: replicate (y - 1) 0.0 : 1.0
    In an equation for ‘identHelper’:
    identHelper y z
    | z == 0 = ([1.0] ++ replicate (y - 1) 0.0) : identHelper y 1
    | y == z = replicate (y - 1) 0.0 : 1.0
    | otherwise
    = (replicate z 0.0 ++ [1.0] ++ replicate (y - z - 1) 0.0)
    : identHelper y (z + 1)









    share|improve this question




























      0












      0








      0








      For class, we have to write some code for a given set of problems. One of these problems is to create an identity matrix in the form of a [[Double]] So far, I have come up with the following code. However, when I try to compile I get the following error, not sure of what I did wrong or what it means



      CODE:



      ident :: Int -> [[Double]]
      ident x = identHelper x 0

      identHelper :: Int -> Int -> [[Double]]
      identHelper y z
      | z == 0 = ([1.0] ++ replicate (y-1) 0.0) : identHelper y 1
      | y == z = replicate (y-1) 0.0 : 1.0
      | otherwise = (replicate z 0.0 ++ [1.0] ++ replicate (y-z-1) 0.0) : identHelper y (z+1)


      ERROR:



       • No instance for (Fractional [[Double]])
      arising from the literal ‘1.0’
      • In the second argument of ‘(:)’, namely ‘1.0’
      In the expression: replicate (y - 1) 0.0 : 1.0
      In an equation for ‘identHelper’:
      identHelper y z
      | z == 0 = ([1.0] ++ replicate (y - 1) 0.0) : identHelper y 1
      | y == z = replicate (y - 1) 0.0 : 1.0
      | otherwise
      = (replicate z 0.0 ++ [1.0] ++ replicate (y - z - 1) 0.0)
      : identHelper y (z + 1)









      share|improve this question
















      For class, we have to write some code for a given set of problems. One of these problems is to create an identity matrix in the form of a [[Double]] So far, I have come up with the following code. However, when I try to compile I get the following error, not sure of what I did wrong or what it means



      CODE:



      ident :: Int -> [[Double]]
      ident x = identHelper x 0

      identHelper :: Int -> Int -> [[Double]]
      identHelper y z
      | z == 0 = ([1.0] ++ replicate (y-1) 0.0) : identHelper y 1
      | y == z = replicate (y-1) 0.0 : 1.0
      | otherwise = (replicate z 0.0 ++ [1.0] ++ replicate (y-z-1) 0.0) : identHelper y (z+1)


      ERROR:



       • No instance for (Fractional [[Double]])
      arising from the literal ‘1.0’
      • In the second argument of ‘(:)’, namely ‘1.0’
      In the expression: replicate (y - 1) 0.0 : 1.0
      In an equation for ‘identHelper’:
      identHelper y z
      | z == 0 = ([1.0] ++ replicate (y - 1) 0.0) : identHelper y 1
      | y == z = replicate (y - 1) 0.0 : 1.0
      | otherwise
      = (replicate z 0.0 ++ [1.0] ++ replicate (y - z - 1) 0.0)
      : identHelper y (z + 1)






      haskell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 12 at 1:23









      Michael Litchard

      2,0012 gold badges19 silver badges44 bronze badges




      2,0012 gold badges19 silver badges44 bronze badges










      asked Mar 28 at 20:40









      Yogesh PatelYogesh Patel

      64 bronze badges




      64 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          6
















          The problem is



           replicate (y-1) 0.0 : 1.0


          BTW you can (and should) always leave away trailing zeroes, so



           replicate (y-1) 0 : 1


          For example, say y=4. Then this reads



           [0,0,0] : 1


          So you're trying to prepend the list [0,0,0] before the... list? 1. How is 1 supposed to be a list?



          I'm not sure what you want there, but one plausible option is [[1]].






          share|improve this answer


























            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/4.0/"u003ecc by-sa 4.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%2f55406500%2fno-instance-for-fractional-double-arising-from-the-literal-1-0%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









            6
















            The problem is



             replicate (y-1) 0.0 : 1.0


            BTW you can (and should) always leave away trailing zeroes, so



             replicate (y-1) 0 : 1


            For example, say y=4. Then this reads



             [0,0,0] : 1


            So you're trying to prepend the list [0,0,0] before the... list? 1. How is 1 supposed to be a list?



            I'm not sure what you want there, but one plausible option is [[1]].






            share|improve this answer





























              6
















              The problem is



               replicate (y-1) 0.0 : 1.0


              BTW you can (and should) always leave away trailing zeroes, so



               replicate (y-1) 0 : 1


              For example, say y=4. Then this reads



               [0,0,0] : 1


              So you're trying to prepend the list [0,0,0] before the... list? 1. How is 1 supposed to be a list?



              I'm not sure what you want there, but one plausible option is [[1]].






              share|improve this answer



























                6














                6










                6









                The problem is



                 replicate (y-1) 0.0 : 1.0


                BTW you can (and should) always leave away trailing zeroes, so



                 replicate (y-1) 0 : 1


                For example, say y=4. Then this reads



                 [0,0,0] : 1


                So you're trying to prepend the list [0,0,0] before the... list? 1. How is 1 supposed to be a list?



                I'm not sure what you want there, but one plausible option is [[1]].






                share|improve this answer













                The problem is



                 replicate (y-1) 0.0 : 1.0


                BTW you can (and should) always leave away trailing zeroes, so



                 replicate (y-1) 0 : 1


                For example, say y=4. Then this reads



                 [0,0,0] : 1


                So you're trying to prepend the list [0,0,0] before the... list? 1. How is 1 supposed to be a list?



                I'm not sure what you want there, but one plausible option is [[1]].







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 20:46









                leftaroundaboutleftaroundabout

                83.6k3 gold badges125 silver badges250 bronze badges




                83.6k3 gold badges125 silver badges250 bronze badges

































                    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%2f55406500%2fno-instance-for-fractional-double-arising-from-the-literal-1-0%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript