Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Haskell rulez!!11

Name: Anonymous 2011-03-28 18:11


instance XmlContent Album where
    fromElem (CElem (Elem "album" [] c0):rest) =
        (\(a,ca)->
           (\(b,cb)->
              (\(c,cc)->
                 (\(d,cd)->
                    (\(e,ce)->
                       (\(f,cf)->
                          (\(g,cg)->
                             (\(h,ch)->
                                (Just (Album a b c d e f g h), rest))
                             (definite fromElem "<notes>" "album" cg))
                          (many fromElem cf))
                       (definite fromElem "<personnel>" "album" ce))
                    (many fromElem cd))
                 (definite fromElem "<coverart>" "album" cc))
              (fromElem cb))
           (definite fromElem "<artist>" "album" ca))
        (definite fromElem "<title>" "album" c0)
    fromElem (CMisc _:rest) = fromElem rest
    fromElem rest = (Nothing, rest)
    toElem (Album a b c d e f g h) =
        [CElem (Elem "album" [] (toElem a ++ toElem b ++ maybe [] toElem c
                                 ++ toElem d ++ concatMap toElem e ++ toElem f ++ concatMap toElem g
                                 ++ toElem h))]
instance XmlContent Title where
    fromElem (CElem (Elem "title" [] c0):rest) =
        (\(a,ca)->
           (Just (Title a), rest))
        (definite fromText "text" "title" c0)
    fromElem (CMisc _:rest) = fromElem rest
    fromElem rest = (Nothing, rest)
    toElem (Title a) =
        [CElem (Elem "title" [] (toText a))]
instance XmlContent Artist where
    fromElem (CElem (Elem "artist" [] c0):rest) =
        (\(a,ca)->
           (Just (Artist a), rest))
        (definite fromText "text" "artist" c0)
    fromElem (CMisc _:rest) = fromElem rest
    fromElem rest = (Nothing, rest)
    toElem (Artist a) =
        [CElem (Elem "artist" [] (toText a))]
instance XmlContent Recording where
    fromElem (CElem (Elem "recording" as []):rest) =
        (Just (fromAttrs as), rest)
    fromElem (CMisc _:rest) = fromElem rest
    fromElem rest = (Nothing, rest)
    toElem as =
        [CElem (Elem "recording" (toAttrs as) [])]
instance XmlAttributes Recording where
    fromAttrs as =
        Recording
          { recordingDate = possibleA fromAttrToStr "date" as
          , recordingPlace = possibleA fromAttrToStr "place" as
          }
    toAttrs v = catMaybes
        [ maybeToAttr toAttrFrStr "date" (recordingDate v)
        , maybeToAttr toAttrFrStr "place" (recordingPlace v)
        ]
instance XmlContent Coverart where
    fromElem (CElem (Elem "coverart" as c0):rest) =
        (\(a,ca)->
           (Just (Coverart (fromAttrs as) a), rest))
        (fromElem c0)
    fromElem (CMisc _:rest) = fromElem rest
    fromElem rest = (Nothing, rest)
    toElem (Coverart as a) =
        [CElem (Elem "coverart" (toAttrs as) (maybe [] toElem a))]

Name: Anonymous 2011-03-29 6:46


                             (definite fromElem "<notes>" "album" cg))
                          (many fromElem cf))
                       (definite fromElem "<personnel>" "album" ce))
                    (many fromElem cd))
                 (definite fromElem "<coverart>" "album" cc))
              (fromElem cb))
           (definite fromElem "<artist>" "album" ca))
        (definite fromElem "<title>" "album" c0)

This is Lisp, not Haskell.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List