[Haskell-beginners] In Search Of a clue... (Defining and making use of a type)
Allen S. Rout
asr at ufl.edu
Mon Dec 12 22:31:02 CET 2011
So, I'm approaching a problem which I think I understand pretty well.
I'm a novice to Haskell, though, and I'm having difficulty even
getting started with e.g. data types and building more complex
structures.
Here's what I'm trying to do; this is an xmonad
customization/extension.
My end goal is thus:
Innermost: a 'Screen Tuple' , which I'm calling a 'ScrUple'. This
represents a statement like 'screen 0 is displaying workspace "mail"'.
Next: A variable-length list of these, I'm calling 'ScrConfig'. It
means something like 'display this workspace on screen 0, that one on
1, etc'.
Next: [ haven't gotten here ] a hash, or something: pairs of 'label :
ScrConfig'. I don't know if the most haskelly way to do that is to
build another type, and then another aggregate of that type..
In PERL, it'd be something vaguely like:
$configs =
{
'initial' => {
\(0,"mail"),
\(1,"web"),
\(2,"jabber")
}
'project' => {
\(4,"editor"),
\(1,"compile"),
\(2,"jabber")
}
};
Here's what I'm doing so far,
----------------
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]
------------------
and I get errors like:
play.hs:17:27:
Couldn't match expected type `ScrUple -> ScrUple'
against inferred type `ScrUple'
In the expression: s2 s1
In the first argument of `ScrConfig', namely `([s2 s1])'
In the expression: ScrConfig ([s2 s1])
play.hs:21:19:
Couldn't match expected type `[t] -> String'
against inferred type `String'
In the second argument of `($)', namely `show sc1 [1]'
In the expression: putStrLn $ show sc1 [1]
In the definition of `main': main = putStrLn $ show sc1 [1]
-------------------
... I feel like I'm thinking about the problem wrong, because this
kind of "Here's how you build up a data structure" doesn't seem to be
in the tutorials. I've been working through LYAH and Gentle
Introduction, but so far haven't found things that feel related.
I'd be delighted with pointers to the right parts of the Fine Manual,
and similarly pleased with discursion on how to think about this data
storage problem from a haskelly point of view.
- Allen S. Rout
More information about the Beginners
mailing list