Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Haskell tree search error

  1. #11
    Join Date
    May 2007
    Location
    USA
    Posts
    373
    Thanks
    2
    Thanked 4 Times in 4 Posts

    Default

    Sure you can. For example toLower from Data.Char is a funtion with the type Char -> Char

    Fire up ghci and try this out:
    Code:
    Prelude> map Data.Char.toLower "He yelled 'HELLO!!!'"
    "he yelled 'hello!!!'"
    Trinithis

  2. #12
    Join Date
    Oct 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That's cool. Handy.

    Would it work for search as above? ... gonna have a quick go.

    ... few mins later...

    Well, couldn't make map work with that, is it possible to work map with a function that takes more inputs than just a list? Had a go of doing it recursively as well:

    Code:
    stringSearch :: String->(Tree Char Float) -> Maybe [Char]
    stringSearch _ Empty = Nothing
    stringSearch "" _ = Nothing
    stringSearch (h:t) tree = search h tree
    Heh... this works for the first char in a string, so I suppose this means it could work for the rest of it. But it's late here, and I'm fairly poor at this at the best of times, so I can't figure out the recursion step right now.

    Anyway, off to bed. Thanks again for helping me figure this stuff out, really useful.

  3. #13
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yes, of course:
    Code:
    import Data.Char (toUpper)
    
    strUp :: String -> String
    strUp = map toUpper
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •