addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1linklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

H-99: Ninety-Nine Haskell Problems

  • Mar 23, 2014 · 2:00 PM
  • This location is shown only to members

Ninety-Nine Haskell Problems is a great place to start gaining familiarity with the Haskell language through basic coding drills and group problem solving.

Let's get together and go through the first several questions as a group.  We can take turns walking through solutions, and learn from our different approaches, styles, and techniques as we go.

NOTE: Depending on the level of interest, we might switch venues to accommodate more attendees.

Join or login to comment.

  • Eugene S.

    Hi guys,

    I just tried to wrap my head around the problem #7 (aka "flatten a nested list") that was discussed a lot because I still don't like the solution found even in the Answers section.

    I think it's possible to implement it without concatMap or (++) or using list reversing:

    data NestedList a = Elem a | List [NestedList a]

    get1st :: NestedList a -> (Maybe a, Maybe (NestedList a))
    get1st (Elem e) = (Just e, Nothing)
    get1st (List []) = (Nothing, Nothing)
    get1st (List (l : ls)) = let (e, l') = get1st l
    tail = maybe (List ls)
    (\h -> List (h : ls)) l'
    in maybe (get1st tail)
    (\e' -> (Just e', Just tail)) e

    flatten :: NestedList a -> [a]
    flatten nl = let (a1, as) = get1st nl
    in maybe [] (: maybe [] flatten as) a1

    main = putStrLn . show . (take 100) . flatten $
    List [List [List [], Elem 4], List [Elem 3], Elem 2]

    March 23, 2014

    • jay b.

      Here's a simpler version with your same goal of not using '++' or 'concatMap':

      https://gist.github.co...­

      It uses a function with an accumulator and flattens in reverse order.

      1 · April 1, 2014

    • Eugene S.

      Hi Jay,

      Your solution is likely the most elegant but it doesn't work for infinite input. It's not lazy in its input parameter. Just try the following:

      main = putStrLn . show . (take 10) . flatten $
      List $ map Elem [1..]

      The proper output is:
      [1,2,3,4,5,6,7,8,9,10]

      :)

      April 2, 2014

  • l g

    Hey, can't seem to get in the building.

    March 23, 2014

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy