Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Non-exhaustive patterns (Jim)
   2. Re:  Non-exhaustive patterns (Brody Berg)
   3. Re:  Non-exhaustive patterns (Brody Berg)
   4. Re:  Non-exhaustive patterns (Jeffrey Brown)


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

Message: 1
Date: Sat, 18 Nov 2017 13:15:51 -0400
From: Jim <jimbo4...@gmail.com>
To: "beginners@haskell.org" <beginners@haskell.org>
Subject: [Haskell-beginners] Non-exhaustive patterns
Message-ID: <bc76b04e-dba2-f58a-0647-697499c74...@gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed

Hey guys,

Thiis is my function below:

notThe :: String -> Maybe String
notThe word
       | word /= "the" = Just word
       | word == [] = Just []
       | otherwise = Nothing

replaceThe :: String -> String
replaceThe word = go (words word)
       where go (x:xs)
               | notThe x == Just [] = []
               | notThe x == Just word = word ++ go xs
               | notThe word == Nothing = " a " ++ go xs


 > replaceThe "what"
"what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns 
in function go

I thought I covered all the potential patterns in my replaceThe 
function. I'm not sure what pattern I've missed, any thoughts?

Best regards,

Jim



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

Message: 2
Date: Sat, 18 Nov 2017 17:48:11 +0000
From: Brody Berg <brodyb...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Non-exhaustive patterns
Message-ID:
        <CAGAyAWOe2mep6376ToqWf4uy=tukb3lfdbrzflstvzxxuwe...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Made some changes to replaceThe to handle the possibility of empty list:

replaceThe :: String -> String
replaceThe word = go $ words word
   where
      go [] = “”
      go (x:xs) =
         case (notThe x) of
            Just x -> x ++ “ “ ++ go xs
            Nothing -> “ a “ ++ go xs

Typed this on a phone, sorry

On Sat, Nov 18, 2017 at 09:16 Jim <jimbo4...@gmail.com> wrote:

> Hey guys,
>
> Thiis is my function below:
>
> notThe :: String -> Maybe String
> notThe word
>        | word /= "the" = Just word
>        | word == [] = Just []
>        | otherwise = Nothing
>
> replaceThe :: String -> String
> replaceThe word = go (words word)
>        where go (x:xs)
>                | notThe x == Just [] = []
>                | notThe x == Just word = word ++ go xs
>                | notThe word == Nothing = " a " ++ go xs
>
>
>  > replaceThe "what"
> "what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns
> in function go
>
> I thought I covered all the potential patterns in my replaceThe
> function. I'm not sure what pattern I've missed, any thoughts?
>
> Best regards,
>
> Jim
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171118/526bfdbb/attachment-0001.html>

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

Message: 3
Date: Sat, 18 Nov 2017 10:46:04 -0800
From: Brody Berg <brodyb...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Non-exhaustive patterns
Message-ID:
        <cagayawnvgcfvxk6yioq4vxndltrywcq35ot9xo+ihza-a0j...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

My complete code:

notThe :: String -> Maybe String
notThe word
  | word == "the" = Nothing
  | otherwise     = Just word

replaceThe :: String -> String
replaceThe word = go $ words word
  where
    go []     = ""
    go (x:xs) =
          case (notThe x) of
            Just x  -> x ++ " " ++ go xs
            Nothing -> " a " ++ go xs

On Sat, Nov 18, 2017 at 9:48 AM, Brody Berg <brodyb...@gmail.com> wrote:

> Made some changes to replaceThe to handle the possibility of empty list:
>
> replaceThe :: String -> String
> replaceThe word = go $ words word
>    where
>       go [] = “”
>       go (x:xs) =
>          case (notThe x) of
>             Just x -> x ++ “ “ ++ go xs
>             Nothing -> “ a “ ++ go xs
>
> Typed this on a phone, sorry
>
> On Sat, Nov 18, 2017 at 09:16 Jim <jimbo4...@gmail.com> wrote:
>
>> Hey guys,
>>
>> Thiis is my function below:
>>
>> notThe :: String -> Maybe String
>> notThe word
>>        | word /= "the" = Just word
>>        | word == [] = Just []
>>        | otherwise = Nothing
>>
>> replaceThe :: String -> String
>> replaceThe word = go (words word)
>>        where go (x:xs)
>>                | notThe x == Just [] = []
>>                | notThe x == Just word = word ++ go xs
>>                | notThe word == Nothing = " a " ++ go xs
>>
>>
>>  > replaceThe "what"
>> "what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns
>> in function go
>>
>> I thought I covered all the potential patterns in my replaceThe
>> function. I'm not sure what pattern I've missed, any thoughts?
>>
>> Best regards,
>>
>> Jim
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171118/2121e9bc/attachment-0001.html>

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

Message: 4
Date: Sat, 18 Nov 2017 11:15:23 -0800
From: Jeffrey Brown <jeffbrown....@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Non-exhaustive patterns
Message-ID:
        <CAEc4Ma2R_2qFnV4uGnN=qNo++ctMS=vsl8dupxbdmqufgu5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

It looks like your latest version works.

This also works:

*Temp> let replaceThe = unwords . map (\i -> if i=="the" then "a" else i) .
words
*Temp> replaceThe "is the bat"
"is a bat"
*Temp>


On Sat, Nov 18, 2017 at 10:46 AM, Brody Berg <brodyb...@gmail.com> wrote:

> My complete code:
>
> notThe :: String -> Maybe String
> notThe word
>   | word == "the" = Nothing
>   | otherwise     = Just word
>
> replaceThe :: String -> String
> replaceThe word = go $ words word
>   where
>     go []     = ""
>     go (x:xs) =
>           case (notThe x) of
>             Just x  -> x ++ " " ++ go xs
>             Nothing -> " a " ++ go xs
>
> On Sat, Nov 18, 2017 at 9:48 AM, Brody Berg <brodyb...@gmail.com> wrote:
>
>> Made some changes to replaceThe to handle the possibility of empty list:
>>
>> replaceThe :: String -> String
>> replaceThe word = go $ words word
>>    where
>>       go [] = “”
>>       go (x:xs) =
>>          case (notThe x) of
>>             Just x -> x ++ “ “ ++ go xs
>>             Nothing -> “ a “ ++ go xs
>>
>> Typed this on a phone, sorry
>>
>> On Sat, Nov 18, 2017 at 09:16 Jim <jimbo4...@gmail.com> wrote:
>>
>>> Hey guys,
>>>
>>> Thiis is my function below:
>>>
>>> notThe :: String -> Maybe String
>>> notThe word
>>>        | word /= "the" = Just word
>>>        | word == [] = Just []
>>>        | otherwise = Nothing
>>>
>>> replaceThe :: String -> String
>>> replaceThe word = go (words word)
>>>        where go (x:xs)
>>>                | notThe x == Just [] = []
>>>                | notThe x == Just word = word ++ go xs
>>>                | notThe word == Nothing = " a " ++ go xs
>>>
>>>
>>>  > replaceThe "what"
>>> "what*** Exception: chap12.hs:(13,13)-(16,55): Non-exhaustive patterns
>>> in function go
>>>
>>> I thought I covered all the potential patterns in my replaceThe
>>> function. I'm not sure what pattern I've missed, any thoughts?
>>>
>>> Best regards,
>>>
>>> Jim
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Jeff Brown | Jeffrey Benjamin Brown
Website <https://msu.edu/~brown202/>   |   Facebook
<https://www.facebook.com/mejeff.younotjeff>   |   LinkedIn
<https://www.linkedin.com/in/jeffreybenjaminbrown>(spammy, so I often miss
messages here)   |   Github <https://github.com/jeffreybenjaminbrown>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171118/03e69d02/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 113, Issue 16
******************************************

Reply via email to