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-28 18:26
holy fuck that sure do look ugly
Name:
Anonymous
2011-03-28 19:39
Haskell is a write-only language.
Name:
Anonymous
2011-03-28 19:40
>>1
That's not pointless. Make it pointless.
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.