[Haskell-cafe] Seeking advice on a style question
Conal Elliott
conal at conal.net
Fri Dec 29 13:30:09 EST 2006
To get another perspective, let's eliminate some unnecessary naming and see
what linear pipelines emerge:
process item mediaKind mediaSize language =
let (numberedQuestions,questionCategories) =
numberQuestions pagemaster $
stripUndisplayedQuestions mediaKind $
appendEndQuestions item
(loadPagemaster item mediaKind mediaSize) $
coalesceParentedQuestions $
validateQuestionContent $
loadQuestions item
(bands,sequenceLayouts) =
buildLayout mediaKind language $
coalesceNAQuestions $
numberedQuestions
in
flip combineRows sequenceLayouts $
paginate item mediaKind mediaSize pagemaster $
groupBands $
resolveCrossReferences $
bands
Warning: I haven't tried to type-check and may have made a clerical error.
Since questionCategories isn't used, use "fst" & eliminate another let.
Then, for my personal preference, and just to mix things up, switch to
"where" style:
process item mediaKind mediaSize language =
flip combineRows sequenceLayouts $
paginate item mediaKind mediaSize pagemaster $
groupBands $
resolveCrossReferences $
bands
where
(bands,sequenceLayouts) =
buildLayout mediaKind language $
coalesceNAQuestions $
fst $
numberQuestions pagemaster $
stripUndisplayedQuestions mediaKind $
appendEndQuestions item
(loadPagemaster item mediaKind mediaSize) $
coalesceParentedQuestions $
validateQuestionContent $
loadQuestions item
Not quite a work of art yet, but the structure is getting clearer to me.
On 12/28/06, Steve Schafer <steve at fenestra.com> wrote:
>
> On Tue, 26 Dec 2006 20:21:45 -0800, you wrote:
>
> >How would this example look if you named only multiply-used expressions?
> >I'd like to see it in a more conventional pointful style with nested
> >expressions. I'm still wondering whether the awkwardness results from
> your
> >writing style or is more inherent. Showing the real variable names may
> also
> >help also.
>
> This is what it looks like "for real":
>
> > process :: Item -> MediaKind -> MediaSize -> Language -> SFO
> > process item mediaKind mediaSize language =
> > let pagemaster = loadPagemaster item mediaKind mediaSize;
> > questions = stripUndisplayedQuestions mediaKind $
> > appendEndQuestions item pagemaster $
> > coalesceParentedQuestions $
> > validateQuestionContent $
> > loadQuestions item;
> > (numberedQuestions,questionCategories) = numberQuestions pagemaster
> questions;
> > numberedQuestions' = coalesceNAQuestions numberedQuestions;
> > (bands,sequenceLayouts) = buildLayout mediaKind language
> numberedQuestions';
> > bands' = resolveCrossReferences bands;
> > groupedBands = groupBands bands';
> > pages = paginate item mediaKind mediaSize pagemaster groupedBands;
> > pages' = combineRows pages;
> > sfo = pages' sequenceLayouts;
> > in sfo
>
> These are the function signatures:
>
> > loadPagemaster :: Item -> MediaKind -> MediaSize -> Pagemaster
> > loadQuestions :: Item -> [Question]
> > validateQuestionContent :: [Question] -> [Question]
> > coalesceParentedQuestions :: [Question] -> [Question]
> > appendEndQuestions :: Item -> Pagemaster -> [Question] -> [Question]
> > stripUndisplayedQuestions :: MediaKind -> [Question] -> [Question]
> > numberQuestions :: Pagemaster -> [Question] ->
> ([NumberedQuestion],[QuestionCategory])
> > coalesceNAQuestions :: [NumberedQuestion] -> [NumberedQuestion]
> > buildLayout :: MediaKind -> Language -> [NumberedQuestion] ->
> ([Band],[SequenceLayout])
> > resolveCrossReferences :: [Band] -> [Band]
> > groupBands :: [Band] -> [[Band]]
> > paginate :: Item -> MediaKind -> MediaSize -> Pagemaster -> [[Band]] ->
> [Page]
> > combineRows :: [Page] -> [Page]
> > createSFO :: [Page] -> [SequenceLayout] -> SFO
>
> MediaKind, MediaSize and Language are simple enumerations; everything
> else is a complex structure.
>
> Steve Schafer
> Fenestra Technologies Corp.
> http://www.fenestra.com/
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20061229/144c94c2/attachment-0001.htm
More information about the Haskell-Cafe
mailing list