[Haskell-beginners] In Search Of a clue... (Defining and making use of a type)

Brent Yorgey byorgey at seas.upenn.edu
Tue Dec 13 02:03:53 CET 2011


On Mon, Dec 12, 2011 at 04:31:02PM -0500, Allen S. Rout wrote:
>
>
> ----------------
>
> data ScrUple = ScrUple { xineramascreen :: Integer
>                          , workspace :: String
>                        } deriving (Show)
>
> data  ScrConfig = ScrConfig [ ScrUple ]  deriving (Show)
>
>
>
> s1 = ScrUple 0 "mail"
> s2 = ScrUple 1 "web"
>
>
> ScrConfig sc1 =ScrConfig( [s2 s1] ) ;
>
> main = putStrLn $  show sc1[1]

Looks OK so far except for the problems of syntax already pointed out
by others.

Proceeding from this point, to build an association between labels and
ScrConfigs, you would use Data.Map. Something like this:

  import qualified Data.Map as M

  type ScrConfigs = M.Map String ScrConfig

  myScrConfigs :: ScrConfigs
  myScrConfigs = M.fromList [ ("initial",
                                [ ScrUple 0 "mail"
                                , ScrUple 1 "web"
                                , ScrUple 2 "jabber"
                                ]
  			      )
                            , ("project",
                                [ ScrUple 0 "editor"
                                , ScrUple 1 "compile"
                                , ScrUple 2 "jabber
                                ]
                              )
                            ]

However, I should point out that this is essentially already
implemented in XMonad.Actions.DynamicWorkspaceGroups.  It may not
currently do exactly what you want -- for example, there's currently
no function provided to initialize the list of workspace configs.  But
it should not be too hard to add.  I'd be happy to help walk you
through the code or help you figure out how to add the features you
want.

-Brent



More information about the Beginners mailing list