Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Compile single file within cabal-dev environment
      (Petar Radosevic)
   2. Re:  Compile single file within cabal-dev environment
      (David McBride)
   3. Re:  Int V.S. Word32 (Sebastian Hungerecker)
   4. Re:  Int V.S. Word32 (Daniel Fischer)
   5.  cabal can't find stdc++ headers or library? (Eric Lasian)
   6. Re:  Compile single file within cabal-dev environment
      (Petar Radosevic)
   7.  questionnaire data design patterns (Alia)


----------------------------------------------------------------------

Message: 1
Date: Sun, 20 Nov 2011 12:29:30 +0100
From: Petar Radosevic <[email protected]>
Subject: [Haskell-beginners] Compile single file within cabal-dev
        environment
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

It seems so trivial, but I haven't been able to do it. I'm trying to
compile a single .hs file whose dependencies are available in
a cabal-dev environment. 

For example, at my website repo [1] you can see that I have
a ``wunki.hs`` which uses Hakyll [2] to create my website. I have
installed Hakyll with cabal-dev. But now I want to ``ghc --make
wunki.hs`` with that cabal-dev environment.

Is this possible?

[1]: https://github.com/wunki/www.wunki.org
[2]: https://github.com/jaspervdj/hakyll
-- 
Petar Rado?evi?, Programmer
wunki.org | @wunki
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: Signature of Petar Radosevic
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111120/8cc99f2b/attachment-0001.pgp>

------------------------------

Message: 2
Date: Sun, 20 Nov 2011 06:41:55 -0500
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Compile single file within cabal-dev
        environment
To: [email protected]
Message-ID:
        <can+tr42waip_m9dj3hqeerepezmtszlrhz9jj-rrhce353n...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

I think cabal-dev is meant to work with actual cabal packages.  So, no
cabal file, no cabal-dev build

virthualenv (note the spelling) will probably work a lot better for
you.  Actually, I'm starting to like it better for pretty much
everything.

On Sun, Nov 20, 2011 at 6:29 AM, Petar Radosevic <[email protected]> wrote:
> It seems so trivial, but I haven't been able to do it. I'm trying to
> compile a single .hs file whose dependencies are available in
> a cabal-dev environment.
>
> For example, at my website repo [1] you can see that I have
> a ``wunki.hs`` which uses Hakyll [2] to create my website. I have
> installed Hakyll with cabal-dev. But now I want to ``ghc --make
> wunki.hs`` with that cabal-dev environment.
>
> Is this possible?
>
> [1]: https://github.com/wunki/www.wunki.org
> [2]: https://github.com/jaspervdj/hakyll
> --
> Petar Rado?evi?, Programmer
> wunki.org | @wunki
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



------------------------------

Message: 3
Date: Sun, 20 Nov 2011 13:53:20 +0100
From: Sebastian Hungerecker <[email protected]>
Subject: Re: [Haskell-beginners] Int V.S. Word32
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

On 20.11.2011 07:50, Haisheng Wu wrote:
> Hmm... I think I made a little confusion so I put my finding here:
> http://haisgwu.info/posts/2011-11-20-euler-problem-14.html
>
> I do got stack overflow thus need several compile opts to fix it.
> Not sure if it is what you mean by "You get overflow using 32-bit types
> here."

No, what he meant was that your n does not always fit into a 32-bit integer,
so the integer will overflow (i.e. once it exceeds its maximum value it will
wrap around and become negative).



------------------------------

Message: 4
Date: Sun, 20 Nov 2011 14:34:38 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Int V.S. Word32
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Sunday 20 November 2011, 13:53:20, Sebastian Hungerecker wrote:
> On 20.11.2011 07:50, Haisheng Wu wrote:
> > Hmm... I think I made a little confusion so I put my finding here:
> > http://haisgwu.info/posts/2011-11-20-euler-problem-14.html
> > 
> > I do got stack overflow thus need several compile opts to fix it.
> > Not sure if it is what you mean by "You get overflow using 32-bit
> > types here."
> 
> No, what he meant was that your n does not always fit into a 32-bit
> integer, so the integer will overflow (i.e. once it exceeds its maximum
> value it will wrap around and become negative).

That.

With Word32 you won't get negative values of course, but the wrapped-around 
values are completely bogus nevertheless.
With signed 32-bit integers, the overflow puts you into an infinite loop of 
negative values for several starting values, the smallest is something 
around 113000 iirc.
With Word32, I never tested what the smallest starting value landing you in 
an infinite loop is, but (2^32-1)/3 surely does (~> 0 ~> 0).



------------------------------

Message: 5
Date: Mon, 21 Nov 2011 00:11:37 +0800
From: Eric Lasian <[email protected]>
Subject: [Haskell-beginners] cabal can't find stdc++ headers or
        library?
To: [email protected]
Message-ID:
        <cao57ng864w6c+stivtacsb77n46vvcvd13ls3140tzow+q-...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi all,

When trying to install double-conversion, I'm getting the following errors.

$ cabal install double-conversion
Resolving dependencies...
Warning: double-conversion.cabal: Ignoring unknown section type: test-suite
Configuring double-conversion-0.2.0.3...
cabal: Missing dependency on a foreign library:
* Missing C library: stdc++
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
cabal: Error: some packages failed to install:
double-conversion-0.2.0.3 failed during the configure step. The exception
was:
ExitFailure 1

So it seems to me that everything is in the expected place: the headers are
in /usr/include/c++/4.* and the library itself is in /usr/lib. Explicitly
forcing cabal to search these directories (with --extra-include-dirs and
--extra-lib-dirs as suggested) doesn't help. Any ideas?

version info: cabal-install version 0.8.0, using version 1.8.0.2 of the
Cabal library, The Glorious Glasgow Haskell Compilation System, version
7.2.1

Thanks,
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111121/c3063d31/attachment-0001.htm>

------------------------------

Message: 6
Date: Sun, 20 Nov 2011 20:33:05 +0100
From: Petar Radosevic <[email protected]>
Subject: Re: [Haskell-beginners] Compile single file within cabal-dev
        environment
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

David McBride wrote on Sun, Nov 20, 2011 at 06:41:55AM -0500:
> I think cabal-dev is meant to work with actual cabal packages.  So, no
> cabal file, no cabal-dev build
> 
> virthualenv (note the spelling) will probably work a lot better for
> you.  Actually, I'm starting to like it better for pretty much
> everything.

That turned out the work perfectly. Thank you for the tip!

-- 
Petar Rado?evi?, Programmer
wunki.org | @wunki
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: Signature of Petar Radosevic
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20111120/6c687323/attachment-0001.pgp>

------------------------------

Message: 7
Date: Mon, 21 Nov 2011 01:02:54 -0800 (PST)
From: Alia <[email protected]>
Subject: [Haskell-beginners] questionnaire data design patterns
To: "[email protected]" <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=iso-8859-1

Hi folks,
As a way to get my head wrapped around haskell data design idioms, I'm 
translating a questionnaire
data model (in python) to haskell, I would appreciate some advice and criticism 
on whether I'm 
going about this the right way.

Here's the initial translation:

<version1.hs>

module Main where

data QuestionType = Open | Test | Choice deriving (Show, Eq)

data Question = Question 
??? { questionName? :: String 
??? , questionText? :: String
??? , questionType? :: QuestionType
??? , answerType??? :: String
??? , correctAnswer :: Maybe String
??? , options?????? :: Maybe [(String, String)]
??? } deriving (Show, Eq)

data QuestionSet = QuestionSet
??? { qsetTitle???? :: String
??? , qsetQuestions :: [Question]
??? } deriving (Show, Eq)

data Questionnaire = Questionnaire
??? { questionnaireTitle??????? :: String
??? , questionnaireQuestionSets :: [QuestionSet]
??? } deriving (Show, Eq)

q1 = Question 
??? { questionName? = "q1"
??? , questionText? = "What is our name?"
??? , questionType? = Open
??? , answerType??? = "str"
??? , correctAnswer = Nothing
??? , options?????? = Nothing
??? }

q2 = Question 
??? { questionName? = "q2"
??? , questionText? = "What is 1+1?"
??? , questionType? = Test
??? , answerType??? = "int"
??? , correctAnswer = Just "2"
??? , options?????? = Nothing
??? }

q3 = Question 
??? { questionName? = "q2"
??? , questionText? = "What is 2+1?"
??? , questionType? = Choice
??? , answerType??? = "int"
??? , correctAnswer = Just "3"
??? , options?????? = Just [("1", "2"), ("2", "3"), ("3", "4")]
??? }

qset = QuestionSet
??? { qsetTitle???? = "simple questions"
??? , qsetQuestions = [q1, q2, q3]
??? }

questionnaire = Questionnaire
??? { questionnaireTitle??????? = "a questionnaire"
??? , questionnaireQuestionSets = [qset]
??? }

</version1.hs>

In this first version, the Question record basically holds all possible fields 
for any kind of question,
and fields which are not used are assigned Nothing thanks to the Maybe monad.

The final type of the answer is specified as a string in the record for later 
conversion.

Now I wanted to take into account a scenario where I don't need to specify the 
answerType by
creating a polymorphic Question type which is specialized to take different 
answertypes.
So I came up with this version:

<version2.hs>


module Main where

import Text.Show.Functions

-- type converters
str = id
int s = read s :: Int
float s = read s :: Double

data QuestionType = Open | Test | Choice deriving (Show, Eq)

data Question a = Question 
??? { questionName??? :: String 
??? , questionText??? :: String
??? , questionType??? :: QuestionType
??? , answerFunc????? :: (String -> a)
??? , correctAnswer?? :: Maybe a
??? , options???????? :: Maybe [(String, a)]
??? } deriving (Show)

data QuestionSet a = QuestionSet
??? { qsetTitle???? :: String
??? , qsetQuestions :: [Question a]
??? } deriving (Show)

data Questionnaire a = Questionnaire
??? { questionnaireTitle??????? :: String
??? , questionnaireQuestionSets :: [QuestionSet a]
??? } deriving (Show)

q1 = Question 
??? { questionName? = "q1"
??? , questionText? = "What is our name?"
??? , questionType? = Open
??? , answerFunc??? = id
??? , correctAnswer = Nothing
??? , options?????? = Nothing
??? }

q2 = Question 
??? { questionName? = "q2"
??? , questionText? = "What is 1+1?"
??? , questionType? = Test
??? , answerFunc??? = int
??? , correctAnswer = Just 2
??? , options?????? = Nothing
??? }

q3 = Question 
??? { questionName? = "q2"
??? , questionText? = "What is 2+1?"
??? , questionType? = Choice
??? , answerFunc??? = int
??? , correctAnswer = Just 3
??? , options?????? = Just [("a", 2), ("b", 3), ("c", 4)]
??? }

qset = QuestionSet
??? { qsetTitle???? = "simple questions"
??? , qsetQuestions = [q1, q2, q3]
??? }

questionnaire = Questionnaire
??? { questionnaireTitle??????? = "a questionnaire"
??? , questionnaireQuestionSets = [qset]
??? }

</version2.hs>

The problem is that now all the questionsets, and questionnaires expect the same
specialized type of question which is obviously not what I want and I get this 
error:

?Couldn't match expected type `[Char]' with actual type `Int'
??? Expected type: Question String
????? Actual type: Question Int
??? In the expression: q2
??? In the `qsetQuestions' field of a record

So what am I doing wrong here? Should I just revert back to version 1 which I 
sense is not
the haskell way.

Many thanks for any help or advice.

Alia



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 41, Issue 26
*****************************************

Reply via email to