Haskell - Iterate Tuple with Different Functions












0















I have been trying to to iterate the cand data in order to apply a function "pt_string".



Pt :: (Float, Float)
Person :: (Pt, Pt, [Pt], Float)


My idea is to call that function "pt_string" in a different way for each element of the tupple.



For example:




  1. pt_string Point (first)

  2. map pt_string [Point]

  3. pt_string Point (second)

  4. show "Tmp"


So far, I got:



pt_string :: pt -> String
pt_string pt = "(" ++ show (fst pt) ++ "," ++ show (snd pt) ++ ")n"


Which works fine. But how can I create cand_to_string :: cand -> String in the above order?



Thanks!










share|improve this question





























    0















    I have been trying to to iterate the cand data in order to apply a function "pt_string".



    Pt :: (Float, Float)
    Person :: (Pt, Pt, [Pt], Float)


    My idea is to call that function "pt_string" in a different way for each element of the tupple.



    For example:




    1. pt_string Point (first)

    2. map pt_string [Point]

    3. pt_string Point (second)

    4. show "Tmp"


    So far, I got:



    pt_string :: pt -> String
    pt_string pt = "(" ++ show (fst pt) ++ "," ++ show (snd pt) ++ ")n"


    Which works fine. But how can I create cand_to_string :: cand -> String in the above order?



    Thanks!










    share|improve this question



























      0












      0








      0








      I have been trying to to iterate the cand data in order to apply a function "pt_string".



      Pt :: (Float, Float)
      Person :: (Pt, Pt, [Pt], Float)


      My idea is to call that function "pt_string" in a different way for each element of the tupple.



      For example:




      1. pt_string Point (first)

      2. map pt_string [Point]

      3. pt_string Point (second)

      4. show "Tmp"


      So far, I got:



      pt_string :: pt -> String
      pt_string pt = "(" ++ show (fst pt) ++ "," ++ show (snd pt) ++ ")n"


      Which works fine. But how can I create cand_to_string :: cand -> String in the above order?



      Thanks!










      share|improve this question
















      I have been trying to to iterate the cand data in order to apply a function "pt_string".



      Pt :: (Float, Float)
      Person :: (Pt, Pt, [Pt], Float)


      My idea is to call that function "pt_string" in a different way for each element of the tupple.



      For example:




      1. pt_string Point (first)

      2. map pt_string [Point]

      3. pt_string Point (second)

      4. show "Tmp"


      So far, I got:



      pt_string :: pt -> String
      pt_string pt = "(" ++ show (fst pt) ++ "," ++ show (snd pt) ++ ")n"


      Which works fine. But how can I create cand_to_string :: cand -> String in the above order?



      Thanks!







      haskell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 18:43







      Ceut

















      asked Nov 23 '18 at 17:00









      CeutCeut

      64




      64
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Assuming



          type Candidate = (Point, Point, [Point], Float)


          you can use



          candidate_to_string :: Candidate -> String
          candidate_to_string (p1, p2, ps, f) =
          "(" ++
          point_to_string p1 ++ ", " ++
          point_to_string p2 ++ ", " ++
          points_to_string ps ++ ", " ++
          show f ++
          ")"


          which relies on



          points_to_string :: [Point] -> String
          points_to_string ps = "[" ++ intercalate ", " (map point_to_string ps) ++ "]"


          exploiting Data.List.intercalate to add commas between the points.



          Also note that, if you simply want the standard list/tuple printing format, you can directly use



          candidate_to_string :: Candidate -> String
          candidate_to_string = show





          share|improve this answer
























          • Thank you! It is perfect!!!!

            – Ceut
            Nov 23 '18 at 18: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%2f53450533%2fhaskell-iterate-tuple-with-different-functions%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









          1














          Assuming



          type Candidate = (Point, Point, [Point], Float)


          you can use



          candidate_to_string :: Candidate -> String
          candidate_to_string (p1, p2, ps, f) =
          "(" ++
          point_to_string p1 ++ ", " ++
          point_to_string p2 ++ ", " ++
          points_to_string ps ++ ", " ++
          show f ++
          ")"


          which relies on



          points_to_string :: [Point] -> String
          points_to_string ps = "[" ++ intercalate ", " (map point_to_string ps) ++ "]"


          exploiting Data.List.intercalate to add commas between the points.



          Also note that, if you simply want the standard list/tuple printing format, you can directly use



          candidate_to_string :: Candidate -> String
          candidate_to_string = show





          share|improve this answer
























          • Thank you! It is perfect!!!!

            – Ceut
            Nov 23 '18 at 18:41
















          1














          Assuming



          type Candidate = (Point, Point, [Point], Float)


          you can use



          candidate_to_string :: Candidate -> String
          candidate_to_string (p1, p2, ps, f) =
          "(" ++
          point_to_string p1 ++ ", " ++
          point_to_string p2 ++ ", " ++
          points_to_string ps ++ ", " ++
          show f ++
          ")"


          which relies on



          points_to_string :: [Point] -> String
          points_to_string ps = "[" ++ intercalate ", " (map point_to_string ps) ++ "]"


          exploiting Data.List.intercalate to add commas between the points.



          Also note that, if you simply want the standard list/tuple printing format, you can directly use



          candidate_to_string :: Candidate -> String
          candidate_to_string = show





          share|improve this answer
























          • Thank you! It is perfect!!!!

            – Ceut
            Nov 23 '18 at 18:41














          1












          1








          1







          Assuming



          type Candidate = (Point, Point, [Point], Float)


          you can use



          candidate_to_string :: Candidate -> String
          candidate_to_string (p1, p2, ps, f) =
          "(" ++
          point_to_string p1 ++ ", " ++
          point_to_string p2 ++ ", " ++
          points_to_string ps ++ ", " ++
          show f ++
          ")"


          which relies on



          points_to_string :: [Point] -> String
          points_to_string ps = "[" ++ intercalate ", " (map point_to_string ps) ++ "]"


          exploiting Data.List.intercalate to add commas between the points.



          Also note that, if you simply want the standard list/tuple printing format, you can directly use



          candidate_to_string :: Candidate -> String
          candidate_to_string = show





          share|improve this answer













          Assuming



          type Candidate = (Point, Point, [Point], Float)


          you can use



          candidate_to_string :: Candidate -> String
          candidate_to_string (p1, p2, ps, f) =
          "(" ++
          point_to_string p1 ++ ", " ++
          point_to_string p2 ++ ", " ++
          points_to_string ps ++ ", " ++
          show f ++
          ")"


          which relies on



          points_to_string :: [Point] -> String
          points_to_string ps = "[" ++ intercalate ", " (map point_to_string ps) ++ "]"


          exploiting Data.List.intercalate to add commas between the points.



          Also note that, if you simply want the standard list/tuple printing format, you can directly use



          candidate_to_string :: Candidate -> String
          candidate_to_string = show






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 17:13









          chichi

          74.6k284140




          74.6k284140













          • Thank you! It is perfect!!!!

            – Ceut
            Nov 23 '18 at 18:41



















          • Thank you! It is perfect!!!!

            – Ceut
            Nov 23 '18 at 18:41

















          Thank you! It is perfect!!!!

          – Ceut
          Nov 23 '18 at 18:41





          Thank you! It is perfect!!!!

          – Ceut
          Nov 23 '18 at 18: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%2f53450533%2fhaskell-iterate-tuple-with-different-functions%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

          Costa Masnaga

          Fotorealismo

          Sidney Franklin