Splitting a word in all possible “Subwords”-All possible combinations W/O imports [duplicate]All possible sublists of a listSplitting a word into all possible 'subwords' - All possible combinationsHow to combinate characters in a string once?How to merge a txt file as a [string] and a output [string] to 1 string in Haskell?Generating all the combinations of a set of boolean variables in HaskellHow to search all words from input string in ios?Modifying and Adding to a list in HaskellNeed explanation of Pseudocode and code - Python 3+List of all possible combinations with unique element from each list without duplicate elementsPrint out all possible strings in C using recursionGet all combinations without duplicatesBoggle program not finding all possible words

Why does Kathryn say this in 12 Monkeys?

Is this half mask suitable for spray painting?

Why doesn’t a normal window produce an apparent rainbow?

How hard would it be to convert a glider into an powered electric aircraft?

Are "living" organ banks practical?

Cause of continuous spectral lines

What is the purpose of building foundations?

What's up with this leaf?

Etymology of 'calcit(r)are'?

Implement Homestuck's Catenative Doomsday Dice Cascader

siunitx error: Invalid numerical input

Strange symbol for two functions

How many times can you cast a card exiled by Release to the Wind?

How can non-coders use programs on Github?

From the list of 3-tuples, how can I select tuples which contain one for more nines?

Translating 'Liber'

Trapping Rain Water

Notation of last measure of a song with a pickup measure

Where does this pattern of naming products come from?

How Can I Tell The Difference Between Unmarked Sugar and Stevia?

What is this solid state starting relay component?

Building a road to escape Earth's gravity by making a pyramid on Antartica

2.8 is missing the Carve option in the Boolean Modifier

How is it possible that Gollum speaks Westron?



Splitting a word in all possible “Subwords”-All possible combinations W/O imports [duplicate]


All possible sublists of a listSplitting a word into all possible 'subwords' - All possible combinationsHow to combinate characters in a string once?How to merge a txt file as a [string] and a output [string] to 1 string in Haskell?Generating all the combinations of a set of boolean variables in HaskellHow to search all words from input string in ios?Modifying and Adding to a list in HaskellNeed explanation of Pseudocode and code - Python 3+List of all possible combinations with unique element from each list without duplicate elementsPrint out all possible strings in C using recursionGet all combinations without duplicatesBoggle program not finding all possible words






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2
















This question already has an answer here:



  • All possible sublists of a list

    1 answer



I am trying to get all the possible combinations of a word in the following manner WITHOUT using any imports:



For example...



 Input: Bang

Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]


This problem has been bothering me for some time and i can't seem to figure out an algorithm to do this..



The code below is what i've done but this gives all the possible combinations of a string but not in the manner that i need.



I tried to implement this python code in haskell but i wasn't able to accomplish it. It basically is the same problem, but you don't have loops in haskell.



Splitting a word into all possible 'subwords' - All possible combinations



The output of the code below is...



["sun","su","s","un","u","n"]



and not



[["s","un"],["s","u","n"],["su","n"]]



 -----------------------------------------------------


substring :: String -> [String]
substring [] = []
substring xs = subs xs ++ substring (tail xs)
where
subs xs = foldl step [] xs
step [] a = [[a]]
step acc a = (head acc ++ [a]) : acc

---------------EXAMPLES OF EXPECTED RESULTS BELOW----------------------------------
Input: Bang
Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]

Input: Sun
Output: [["s","un"],["s","u","n"],["su","n"]]









share|improve this question













marked as duplicate by dfeuer haskell
Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 25 at 3:50


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























    2
















    This question already has an answer here:



    • All possible sublists of a list

      1 answer



    I am trying to get all the possible combinations of a word in the following manner WITHOUT using any imports:



    For example...



     Input: Bang

    Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]


    This problem has been bothering me for some time and i can't seem to figure out an algorithm to do this..



    The code below is what i've done but this gives all the possible combinations of a string but not in the manner that i need.



    I tried to implement this python code in haskell but i wasn't able to accomplish it. It basically is the same problem, but you don't have loops in haskell.



    Splitting a word into all possible 'subwords' - All possible combinations



    The output of the code below is...



    ["sun","su","s","un","u","n"]



    and not



    [["s","un"],["s","u","n"],["su","n"]]



     -----------------------------------------------------


    substring :: String -> [String]
    substring [] = []
    substring xs = subs xs ++ substring (tail xs)
    where
    subs xs = foldl step [] xs
    step [] a = [[a]]
    step acc a = (head acc ++ [a]) : acc

    ---------------EXAMPLES OF EXPECTED RESULTS BELOW----------------------------------
    Input: Bang
    Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]

    Input: Sun
    Output: [["s","un"],["s","u","n"],["su","n"]]









    share|improve this question













    marked as duplicate by dfeuer haskell
    Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Mar 25 at 3:50


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.




















      2












      2








      2


      1







      This question already has an answer here:



      • All possible sublists of a list

        1 answer



      I am trying to get all the possible combinations of a word in the following manner WITHOUT using any imports:



      For example...



       Input: Bang

      Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]


      This problem has been bothering me for some time and i can't seem to figure out an algorithm to do this..



      The code below is what i've done but this gives all the possible combinations of a string but not in the manner that i need.



      I tried to implement this python code in haskell but i wasn't able to accomplish it. It basically is the same problem, but you don't have loops in haskell.



      Splitting a word into all possible 'subwords' - All possible combinations



      The output of the code below is...



      ["sun","su","s","un","u","n"]



      and not



      [["s","un"],["s","u","n"],["su","n"]]



       -----------------------------------------------------


      substring :: String -> [String]
      substring [] = []
      substring xs = subs xs ++ substring (tail xs)
      where
      subs xs = foldl step [] xs
      step [] a = [[a]]
      step acc a = (head acc ++ [a]) : acc

      ---------------EXAMPLES OF EXPECTED RESULTS BELOW----------------------------------
      Input: Bang
      Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]

      Input: Sun
      Output: [["s","un"],["s","u","n"],["su","n"]]









      share|improve this question















      This question already has an answer here:



      • All possible sublists of a list

        1 answer



      I am trying to get all the possible combinations of a word in the following manner WITHOUT using any imports:



      For example...



       Input: Bang

      Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]


      This problem has been bothering me for some time and i can't seem to figure out an algorithm to do this..



      The code below is what i've done but this gives all the possible combinations of a string but not in the manner that i need.



      I tried to implement this python code in haskell but i wasn't able to accomplish it. It basically is the same problem, but you don't have loops in haskell.



      Splitting a word into all possible 'subwords' - All possible combinations



      The output of the code below is...



      ["sun","su","s","un","u","n"]



      and not



      [["s","un"],["s","u","n"],["su","n"]]



       -----------------------------------------------------


      substring :: String -> [String]
      substring [] = []
      substring xs = subs xs ++ substring (tail xs)
      where
      subs xs = foldl step [] xs
      step [] a = [[a]]
      step acc a = (head acc ++ [a]) : acc

      ---------------EXAMPLES OF EXPECTED RESULTS BELOW----------------------------------
      Input: Bang
      Output: [['B','ang'], ['Ba','ng'], ['Ban','g'], ['B','a','ng'], ['B','an','g'], ['Ba','n','g'], ['B','a','n','g']]

      Input: Sun
      Output: [["s","un"],["s","u","n"],["su","n"]]




      This question already has an answer here:



      • All possible sublists of a list

        1 answer







      haskell recursion haskell-platform






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 15:29









      RottenCrusaderRottenCrusader

      163




      163




      marked as duplicate by dfeuer haskell
      Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 25 at 3:50


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by dfeuer haskell
      Users with the  haskell badge can single-handedly close haskell questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Mar 25 at 3:50


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Recursion is here to help. Say we have a non-empty list x : xs. We want to know subString (x : xs). We apply our solution recursively to xs, so subString xs is a list of all solutions for xs. However we still have that single x. There are exactly two ways to bring back x in the solution for x : xs which covers for the entire solution set of subString (x : xs):



          • Bring x back without attaching it to its neighbor. If we have x : xs = "Bang" then x will be 'B' and xs will be "ang" and subString "ang" will be [["ang"],["an","g"],["a","ng"],["a","n","g"]]. This is done by [[x] : u | u <- subString xs]. Here u is a list of Strings, for example ["a","ng"]. As x is a character we must turn it to a String, this is done by [x], attaching it to the head of the list goes by [x] : u, so ["B","a","ng"]. The list comprehension will do it for all elements in subString xs.

          • Bring x back attaching it to its neighbors. An arbitrary solution of subString xs will look like u : us. We want to attach x to the first element of u : us which is u. So x : u. For example u : us = ["a","n","g"] so u will be "a" and us will be ["n","g"]. Attaching 'B' to "a" is done by 'B' : "a" and will give "Ba". We have to put "Ba back in the list so (x : u) : us. The list comp[rehension looks like [(x : u) : us | (u : us) <- subString xs].

          We are still left with the case of a String of a single character. We write [x] for that where x is the single character. So subString [x] will be [[[x]]].



          We have to join the solutions together so



          subString :: String -> [[String]]
          subString [x] = [[[x]]]
          subString (x : xs) = [(x : u) : us | (u : us) <- subString xs] ++ [[x] : u | u <- subString xs]


          Example



          *Main> subString "Bang"
          [["Bang"],["Ban","g"],["Ba","ng"],["Ba","n","g"],["B","ang"],["B","an","g"],["B","a","ng"],["B","a","n","g"]]





          share|improve this answer




















          • 1





            Note that subString' "" will crash your entire program with a non-exhaustive patterns error.

            – Joseph Sible
            Mar 24 at 17:12











          • @JosephSible True but easy to fix if he wants.

            – Elmex80s
            Mar 24 at 17:13











          • Thanks for the quick answer!

            – RottenCrusader
            Mar 24 at 17:20











          • @Elmex80s could you furtherly elaborate how the code works?I am having problems understanding it because i am new to haskell. I am assuming that it is something like the answer below given by JosephSible but im having troubles understanding its logic.Thanks again in advance!

            – RottenCrusader
            Mar 24 at 17:41











          • here it is for you

            – Elmex80s
            Mar 24 at 23:00


















          2














          Note that the type signature of your attempt is wrong. You want all of the combinations of subword splits, which is a list of list of strings, but your type is just a list of list of strings.



          This will work:



          onHead :: (a -> a) -> [a] -> [a]
          onHead _ [] = []
          onHead f (x:xs) = f x:xs

          combos :: [a] -> [[[a]]]
          combos [] = [[]]
          combos [x] = [[[x]]]
          combos (x:xs) = [([x]:), onHead (x:)] <*> combos xs


          onHead should be self-explanatory: perform the given function on the head of a list. combos recurses as follows: the subwords of a string are the subwords of its tail, with two possibilities for each: either the head is its own subword, or it's tacked onto the beginning of the first subword.




          Update: Here's another (IMO cleaner) approach:



          combos :: Foldable t => t a -> [[[a]]]
          combos = foldr (concatMap . go) [[]]
          where go x l = ([x]:l):case l of
          [] -> []
          h:t -> [(x:h):t]


          It's using the same technique as above, just with a cleaner implementation.






          share|improve this answer

























          • Thanks! Works like a charm but i accepted the 1st answer just for the sake of being the 1st.Thanks alot though really!

            – RottenCrusader
            Mar 24 at 17:20











          • @rempakos You can give +1 to answers if you think it is worth it, even if you do not accept it as the answer.

            – Elmex80s
            Mar 24 at 17:22











          • @Elmex80s You need 15 rep to upvote, which rempakos doesn't have yet.

            – Joseph Sible
            Mar 24 at 17:23











          • I tried upvoting but it didn't let me because i don't have the rep, but ill visit back and upvote if i reach that number!Thanks again!

            – RottenCrusader
            Mar 24 at 17:25

















          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Recursion is here to help. Say we have a non-empty list x : xs. We want to know subString (x : xs). We apply our solution recursively to xs, so subString xs is a list of all solutions for xs. However we still have that single x. There are exactly two ways to bring back x in the solution for x : xs which covers for the entire solution set of subString (x : xs):



          • Bring x back without attaching it to its neighbor. If we have x : xs = "Bang" then x will be 'B' and xs will be "ang" and subString "ang" will be [["ang"],["an","g"],["a","ng"],["a","n","g"]]. This is done by [[x] : u | u <- subString xs]. Here u is a list of Strings, for example ["a","ng"]. As x is a character we must turn it to a String, this is done by [x], attaching it to the head of the list goes by [x] : u, so ["B","a","ng"]. The list comprehension will do it for all elements in subString xs.

          • Bring x back attaching it to its neighbors. An arbitrary solution of subString xs will look like u : us. We want to attach x to the first element of u : us which is u. So x : u. For example u : us = ["a","n","g"] so u will be "a" and us will be ["n","g"]. Attaching 'B' to "a" is done by 'B' : "a" and will give "Ba". We have to put "Ba back in the list so (x : u) : us. The list comp[rehension looks like [(x : u) : us | (u : us) <- subString xs].

          We are still left with the case of a String of a single character. We write [x] for that where x is the single character. So subString [x] will be [[[x]]].



          We have to join the solutions together so



          subString :: String -> [[String]]
          subString [x] = [[[x]]]
          subString (x : xs) = [(x : u) : us | (u : us) <- subString xs] ++ [[x] : u | u <- subString xs]


          Example



          *Main> subString "Bang"
          [["Bang"],["Ban","g"],["Ba","ng"],["Ba","n","g"],["B","ang"],["B","an","g"],["B","a","ng"],["B","a","n","g"]]





          share|improve this answer




















          • 1





            Note that subString' "" will crash your entire program with a non-exhaustive patterns error.

            – Joseph Sible
            Mar 24 at 17:12











          • @JosephSible True but easy to fix if he wants.

            – Elmex80s
            Mar 24 at 17:13











          • Thanks for the quick answer!

            – RottenCrusader
            Mar 24 at 17:20











          • @Elmex80s could you furtherly elaborate how the code works?I am having problems understanding it because i am new to haskell. I am assuming that it is something like the answer below given by JosephSible but im having troubles understanding its logic.Thanks again in advance!

            – RottenCrusader
            Mar 24 at 17:41











          • here it is for you

            – Elmex80s
            Mar 24 at 23:00















          1














          Recursion is here to help. Say we have a non-empty list x : xs. We want to know subString (x : xs). We apply our solution recursively to xs, so subString xs is a list of all solutions for xs. However we still have that single x. There are exactly two ways to bring back x in the solution for x : xs which covers for the entire solution set of subString (x : xs):



          • Bring x back without attaching it to its neighbor. If we have x : xs = "Bang" then x will be 'B' and xs will be "ang" and subString "ang" will be [["ang"],["an","g"],["a","ng"],["a","n","g"]]. This is done by [[x] : u | u <- subString xs]. Here u is a list of Strings, for example ["a","ng"]. As x is a character we must turn it to a String, this is done by [x], attaching it to the head of the list goes by [x] : u, so ["B","a","ng"]. The list comprehension will do it for all elements in subString xs.

          • Bring x back attaching it to its neighbors. An arbitrary solution of subString xs will look like u : us. We want to attach x to the first element of u : us which is u. So x : u. For example u : us = ["a","n","g"] so u will be "a" and us will be ["n","g"]. Attaching 'B' to "a" is done by 'B' : "a" and will give "Ba". We have to put "Ba back in the list so (x : u) : us. The list comp[rehension looks like [(x : u) : us | (u : us) <- subString xs].

          We are still left with the case of a String of a single character. We write [x] for that where x is the single character. So subString [x] will be [[[x]]].



          We have to join the solutions together so



          subString :: String -> [[String]]
          subString [x] = [[[x]]]
          subString (x : xs) = [(x : u) : us | (u : us) <- subString xs] ++ [[x] : u | u <- subString xs]


          Example



          *Main> subString "Bang"
          [["Bang"],["Ban","g"],["Ba","ng"],["Ba","n","g"],["B","ang"],["B","an","g"],["B","a","ng"],["B","a","n","g"]]





          share|improve this answer




















          • 1





            Note that subString' "" will crash your entire program with a non-exhaustive patterns error.

            – Joseph Sible
            Mar 24 at 17:12











          • @JosephSible True but easy to fix if he wants.

            – Elmex80s
            Mar 24 at 17:13











          • Thanks for the quick answer!

            – RottenCrusader
            Mar 24 at 17:20











          • @Elmex80s could you furtherly elaborate how the code works?I am having problems understanding it because i am new to haskell. I am assuming that it is something like the answer below given by JosephSible but im having troubles understanding its logic.Thanks again in advance!

            – RottenCrusader
            Mar 24 at 17:41











          • here it is for you

            – Elmex80s
            Mar 24 at 23:00













          1












          1








          1







          Recursion is here to help. Say we have a non-empty list x : xs. We want to know subString (x : xs). We apply our solution recursively to xs, so subString xs is a list of all solutions for xs. However we still have that single x. There are exactly two ways to bring back x in the solution for x : xs which covers for the entire solution set of subString (x : xs):



          • Bring x back without attaching it to its neighbor. If we have x : xs = "Bang" then x will be 'B' and xs will be "ang" and subString "ang" will be [["ang"],["an","g"],["a","ng"],["a","n","g"]]. This is done by [[x] : u | u <- subString xs]. Here u is a list of Strings, for example ["a","ng"]. As x is a character we must turn it to a String, this is done by [x], attaching it to the head of the list goes by [x] : u, so ["B","a","ng"]. The list comprehension will do it for all elements in subString xs.

          • Bring x back attaching it to its neighbors. An arbitrary solution of subString xs will look like u : us. We want to attach x to the first element of u : us which is u. So x : u. For example u : us = ["a","n","g"] so u will be "a" and us will be ["n","g"]. Attaching 'B' to "a" is done by 'B' : "a" and will give "Ba". We have to put "Ba back in the list so (x : u) : us. The list comp[rehension looks like [(x : u) : us | (u : us) <- subString xs].

          We are still left with the case of a String of a single character. We write [x] for that where x is the single character. So subString [x] will be [[[x]]].



          We have to join the solutions together so



          subString :: String -> [[String]]
          subString [x] = [[[x]]]
          subString (x : xs) = [(x : u) : us | (u : us) <- subString xs] ++ [[x] : u | u <- subString xs]


          Example



          *Main> subString "Bang"
          [["Bang"],["Ban","g"],["Ba","ng"],["Ba","n","g"],["B","ang"],["B","an","g"],["B","a","ng"],["B","a","n","g"]]





          share|improve this answer















          Recursion is here to help. Say we have a non-empty list x : xs. We want to know subString (x : xs). We apply our solution recursively to xs, so subString xs is a list of all solutions for xs. However we still have that single x. There are exactly two ways to bring back x in the solution for x : xs which covers for the entire solution set of subString (x : xs):



          • Bring x back without attaching it to its neighbor. If we have x : xs = "Bang" then x will be 'B' and xs will be "ang" and subString "ang" will be [["ang"],["an","g"],["a","ng"],["a","n","g"]]. This is done by [[x] : u | u <- subString xs]. Here u is a list of Strings, for example ["a","ng"]. As x is a character we must turn it to a String, this is done by [x], attaching it to the head of the list goes by [x] : u, so ["B","a","ng"]. The list comprehension will do it for all elements in subString xs.

          • Bring x back attaching it to its neighbors. An arbitrary solution of subString xs will look like u : us. We want to attach x to the first element of u : us which is u. So x : u. For example u : us = ["a","n","g"] so u will be "a" and us will be ["n","g"]. Attaching 'B' to "a" is done by 'B' : "a" and will give "Ba". We have to put "Ba back in the list so (x : u) : us. The list comp[rehension looks like [(x : u) : us | (u : us) <- subString xs].

          We are still left with the case of a String of a single character. We write [x] for that where x is the single character. So subString [x] will be [[[x]]].



          We have to join the solutions together so



          subString :: String -> [[String]]
          subString [x] = [[[x]]]
          subString (x : xs) = [(x : u) : us | (u : us) <- subString xs] ++ [[x] : u | u <- subString xs]


          Example



          *Main> subString "Bang"
          [["Bang"],["Ban","g"],["Ba","ng"],["Ba","n","g"],["B","ang"],["B","an","g"],["B","a","ng"],["B","a","n","g"]]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 24 at 22:59

























          answered Mar 24 at 17:09









          Elmex80sElmex80s

          2,3551816




          2,3551816







          • 1





            Note that subString' "" will crash your entire program with a non-exhaustive patterns error.

            – Joseph Sible
            Mar 24 at 17:12











          • @JosephSible True but easy to fix if he wants.

            – Elmex80s
            Mar 24 at 17:13











          • Thanks for the quick answer!

            – RottenCrusader
            Mar 24 at 17:20











          • @Elmex80s could you furtherly elaborate how the code works?I am having problems understanding it because i am new to haskell. I am assuming that it is something like the answer below given by JosephSible but im having troubles understanding its logic.Thanks again in advance!

            – RottenCrusader
            Mar 24 at 17:41











          • here it is for you

            – Elmex80s
            Mar 24 at 23:00












          • 1





            Note that subString' "" will crash your entire program with a non-exhaustive patterns error.

            – Joseph Sible
            Mar 24 at 17:12











          • @JosephSible True but easy to fix if he wants.

            – Elmex80s
            Mar 24 at 17:13











          • Thanks for the quick answer!

            – RottenCrusader
            Mar 24 at 17:20











          • @Elmex80s could you furtherly elaborate how the code works?I am having problems understanding it because i am new to haskell. I am assuming that it is something like the answer below given by JosephSible but im having troubles understanding its logic.Thanks again in advance!

            – RottenCrusader
            Mar 24 at 17:41











          • here it is for you

            – Elmex80s
            Mar 24 at 23:00







          1




          1





          Note that subString' "" will crash your entire program with a non-exhaustive patterns error.

          – Joseph Sible
          Mar 24 at 17:12





          Note that subString' "" will crash your entire program with a non-exhaustive patterns error.

          – Joseph Sible
          Mar 24 at 17:12













          @JosephSible True but easy to fix if he wants.

          – Elmex80s
          Mar 24 at 17:13





          @JosephSible True but easy to fix if he wants.

          – Elmex80s
          Mar 24 at 17:13













          Thanks for the quick answer!

          – RottenCrusader
          Mar 24 at 17:20





          Thanks for the quick answer!

          – RottenCrusader
          Mar 24 at 17:20













          @Elmex80s could you furtherly elaborate how the code works?I am having problems understanding it because i am new to haskell. I am assuming that it is something like the answer below given by JosephSible but im having troubles understanding its logic.Thanks again in advance!

          – RottenCrusader
          Mar 24 at 17:41





          @Elmex80s could you furtherly elaborate how the code works?I am having problems understanding it because i am new to haskell. I am assuming that it is something like the answer below given by JosephSible but im having troubles understanding its logic.Thanks again in advance!

          – RottenCrusader
          Mar 24 at 17:41













          here it is for you

          – Elmex80s
          Mar 24 at 23:00





          here it is for you

          – Elmex80s
          Mar 24 at 23:00













          2














          Note that the type signature of your attempt is wrong. You want all of the combinations of subword splits, which is a list of list of strings, but your type is just a list of list of strings.



          This will work:



          onHead :: (a -> a) -> [a] -> [a]
          onHead _ [] = []
          onHead f (x:xs) = f x:xs

          combos :: [a] -> [[[a]]]
          combos [] = [[]]
          combos [x] = [[[x]]]
          combos (x:xs) = [([x]:), onHead (x:)] <*> combos xs


          onHead should be self-explanatory: perform the given function on the head of a list. combos recurses as follows: the subwords of a string are the subwords of its tail, with two possibilities for each: either the head is its own subword, or it's tacked onto the beginning of the first subword.




          Update: Here's another (IMO cleaner) approach:



          combos :: Foldable t => t a -> [[[a]]]
          combos = foldr (concatMap . go) [[]]
          where go x l = ([x]:l):case l of
          [] -> []
          h:t -> [(x:h):t]


          It's using the same technique as above, just with a cleaner implementation.






          share|improve this answer

























          • Thanks! Works like a charm but i accepted the 1st answer just for the sake of being the 1st.Thanks alot though really!

            – RottenCrusader
            Mar 24 at 17:20











          • @rempakos You can give +1 to answers if you think it is worth it, even if you do not accept it as the answer.

            – Elmex80s
            Mar 24 at 17:22











          • @Elmex80s You need 15 rep to upvote, which rempakos doesn't have yet.

            – Joseph Sible
            Mar 24 at 17:23











          • I tried upvoting but it didn't let me because i don't have the rep, but ill visit back and upvote if i reach that number!Thanks again!

            – RottenCrusader
            Mar 24 at 17:25















          2














          Note that the type signature of your attempt is wrong. You want all of the combinations of subword splits, which is a list of list of strings, but your type is just a list of list of strings.



          This will work:



          onHead :: (a -> a) -> [a] -> [a]
          onHead _ [] = []
          onHead f (x:xs) = f x:xs

          combos :: [a] -> [[[a]]]
          combos [] = [[]]
          combos [x] = [[[x]]]
          combos (x:xs) = [([x]:), onHead (x:)] <*> combos xs


          onHead should be self-explanatory: perform the given function on the head of a list. combos recurses as follows: the subwords of a string are the subwords of its tail, with two possibilities for each: either the head is its own subword, or it's tacked onto the beginning of the first subword.




          Update: Here's another (IMO cleaner) approach:



          combos :: Foldable t => t a -> [[[a]]]
          combos = foldr (concatMap . go) [[]]
          where go x l = ([x]:l):case l of
          [] -> []
          h:t -> [(x:h):t]


          It's using the same technique as above, just with a cleaner implementation.






          share|improve this answer

























          • Thanks! Works like a charm but i accepted the 1st answer just for the sake of being the 1st.Thanks alot though really!

            – RottenCrusader
            Mar 24 at 17:20











          • @rempakos You can give +1 to answers if you think it is worth it, even if you do not accept it as the answer.

            – Elmex80s
            Mar 24 at 17:22











          • @Elmex80s You need 15 rep to upvote, which rempakos doesn't have yet.

            – Joseph Sible
            Mar 24 at 17:23











          • I tried upvoting but it didn't let me because i don't have the rep, but ill visit back and upvote if i reach that number!Thanks again!

            – RottenCrusader
            Mar 24 at 17:25













          2












          2








          2







          Note that the type signature of your attempt is wrong. You want all of the combinations of subword splits, which is a list of list of strings, but your type is just a list of list of strings.



          This will work:



          onHead :: (a -> a) -> [a] -> [a]
          onHead _ [] = []
          onHead f (x:xs) = f x:xs

          combos :: [a] -> [[[a]]]
          combos [] = [[]]
          combos [x] = [[[x]]]
          combos (x:xs) = [([x]:), onHead (x:)] <*> combos xs


          onHead should be self-explanatory: perform the given function on the head of a list. combos recurses as follows: the subwords of a string are the subwords of its tail, with two possibilities for each: either the head is its own subword, or it's tacked onto the beginning of the first subword.




          Update: Here's another (IMO cleaner) approach:



          combos :: Foldable t => t a -> [[[a]]]
          combos = foldr (concatMap . go) [[]]
          where go x l = ([x]:l):case l of
          [] -> []
          h:t -> [(x:h):t]


          It's using the same technique as above, just with a cleaner implementation.






          share|improve this answer















          Note that the type signature of your attempt is wrong. You want all of the combinations of subword splits, which is a list of list of strings, but your type is just a list of list of strings.



          This will work:



          onHead :: (a -> a) -> [a] -> [a]
          onHead _ [] = []
          onHead f (x:xs) = f x:xs

          combos :: [a] -> [[[a]]]
          combos [] = [[]]
          combos [x] = [[[x]]]
          combos (x:xs) = [([x]:), onHead (x:)] <*> combos xs


          onHead should be self-explanatory: perform the given function on the head of a list. combos recurses as follows: the subwords of a string are the subwords of its tail, with two possibilities for each: either the head is its own subword, or it's tacked onto the beginning of the first subword.




          Update: Here's another (IMO cleaner) approach:



          combos :: Foldable t => t a -> [[[a]]]
          combos = foldr (concatMap . go) [[]]
          where go x l = ([x]:l):case l of
          [] -> []
          h:t -> [(x:h):t]


          It's using the same technique as above, just with a cleaner implementation.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 14 at 0:13

























          answered Mar 24 at 17:09









          Joseph SibleJoseph Sible

          9,09031543




          9,09031543












          • Thanks! Works like a charm but i accepted the 1st answer just for the sake of being the 1st.Thanks alot though really!

            – RottenCrusader
            Mar 24 at 17:20











          • @rempakos You can give +1 to answers if you think it is worth it, even if you do not accept it as the answer.

            – Elmex80s
            Mar 24 at 17:22











          • @Elmex80s You need 15 rep to upvote, which rempakos doesn't have yet.

            – Joseph Sible
            Mar 24 at 17:23











          • I tried upvoting but it didn't let me because i don't have the rep, but ill visit back and upvote if i reach that number!Thanks again!

            – RottenCrusader
            Mar 24 at 17:25

















          • Thanks! Works like a charm but i accepted the 1st answer just for the sake of being the 1st.Thanks alot though really!

            – RottenCrusader
            Mar 24 at 17:20











          • @rempakos You can give +1 to answers if you think it is worth it, even if you do not accept it as the answer.

            – Elmex80s
            Mar 24 at 17:22











          • @Elmex80s You need 15 rep to upvote, which rempakos doesn't have yet.

            – Joseph Sible
            Mar 24 at 17:23











          • I tried upvoting but it didn't let me because i don't have the rep, but ill visit back and upvote if i reach that number!Thanks again!

            – RottenCrusader
            Mar 24 at 17:25
















          Thanks! Works like a charm but i accepted the 1st answer just for the sake of being the 1st.Thanks alot though really!

          – RottenCrusader
          Mar 24 at 17:20





          Thanks! Works like a charm but i accepted the 1st answer just for the sake of being the 1st.Thanks alot though really!

          – RottenCrusader
          Mar 24 at 17:20













          @rempakos You can give +1 to answers if you think it is worth it, even if you do not accept it as the answer.

          – Elmex80s
          Mar 24 at 17:22





          @rempakos You can give +1 to answers if you think it is worth it, even if you do not accept it as the answer.

          – Elmex80s
          Mar 24 at 17:22













          @Elmex80s You need 15 rep to upvote, which rempakos doesn't have yet.

          – Joseph Sible
          Mar 24 at 17:23





          @Elmex80s You need 15 rep to upvote, which rempakos doesn't have yet.

          – Joseph Sible
          Mar 24 at 17:23













          I tried upvoting but it didn't let me because i don't have the rep, but ill visit back and upvote if i reach that number!Thanks again!

          – RottenCrusader
          Mar 24 at 17:25





          I tried upvoting but it didn't let me because i don't have the rep, but ill visit back and upvote if i reach that number!Thanks again!

          – RottenCrusader
          Mar 24 at 17:25



          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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현