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.  Static records (CSV tables as modules) (Mark Fredrickson)
   2. Re:  Static records (CSV tables as modules) (Lyndon Maydwell)
   3. Re:  Static records (CSV tables as modules) (Ben Gamari)
   4.  Best way to have a fresh&updated Haskell installation
      (Christian Espinoza L.)
   5. Re:  Best way to have a fresh&updated Haskell     installation
      (Christopher Allen)
   6. Re:  installing cabal 1.20 on linux mint debian edition
      (LMDE) (Ovidiu Deac)


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

Message: 1
Date: Fri, 30 May 2014 17:50:21 -0500
From: Mark Fredrickson <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Static records (CSV tables as modules)
Message-ID:
        <caoe7hbhszco_zmv-hnipkguuodwhukiv8spnx+6c+owdwhw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hello,

I writing a program that operates on some static data, currently saved in
CSV files. Right now I parse the files at run time and then generate
hashmap tables to connect the different data.

Since I'm only ever operating on static data, I'm wondering if I can
generate module files that capture the records as a sum type. To access the
fields of the records, I could then imagine functions that exhaustively map
the constructors to the data.

Do any tools to generate .hs files from CSV or other formats exist? Insofar
as this question has been asked before, the recommendation is "use Template
Haskell", which makes sense, but is a less complete solution than I'm
hoping for.

Here's example of what what would be generated in literal Haskell source:

-- input.csv
name, age, someValue
"abc", 1, 3.0
"xyz3", 99, -5.9

-- Input.hs
module Input where

data Row = R1 | R2

name :: Row -> String
name R1 = "abc"
name R2 = "xyz3"

age :: Row -> Integer
age R1 = 1
age R2 = 99

-- likewise for the function someValue

Thanks,
-M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140530/ba5d9392/attachment-0001.html>

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

Message: 2
Date: Sat, 31 May 2014 09:07:00 +1000
From: Lyndon Maydwell <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Static records (CSV tables as
        modules)
Message-ID:
        <CAM5QZtzneGohkEREHd48t3TnxsjsH+ZJSsa=YApGsFwDCWdJ=w...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

I've never heard of a csv code-generation tool that works like this,
but it doesn't look like it would be too hard to hand-roll one, or do
you want to bypass code-generation?

 - Lyndon

On Sat, May 31, 2014 at 8:50 AM, Mark Fredrickson
<[email protected]> wrote:
> Hello,
>
> I writing a program that operates on some static data, currently saved in
> CSV files. Right now I parse the files at run time and then generate hashmap
> tables to connect the different data.
>
> Since I'm only ever operating on static data, I'm wondering if I can
> generate module files that capture the records as a sum type. To access the
> fields of the records, I could then imagine functions that exhaustively map
> the constructors to the data.
>
> Do any tools to generate .hs files from CSV or other formats exist? Insofar
> as this question has been asked before, the recommendation is "use Template
> Haskell", which makes sense, but is a less complete solution than I'm hoping
> for.
>
> Here's example of what what would be generated in literal Haskell source:
>
> -- input.csv
> name, age, someValue
> "abc", 1, 3.0
> "xyz3", 99, -5.9
>
> -- Input.hs
> module Input where
>
> data Row = R1 | R2
>
> name :: Row -> String
> name R1 = "abc"
> name R2 = "xyz3"
>
> age :: Row -> Integer
> age R1 = 1
> age R2 = 99
>
> -- likewise for the function someValue
>
> Thanks,
> -M
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>


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

Message: 3
Date: Fri, 30 May 2014 19:40:53 -0400
From: Ben Gamari <[email protected]>
To: Mark Fredrickson <[email protected]>,
        [email protected]
Subject: Re: [Haskell-beginners] Static records (CSV tables as
        modules)
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Mark Fredrickson <[email protected]> writes:

> Hello,
>
> I writing a program that operates on some static data, currently saved in
> CSV files. Right now I parse the files at run time and then generate
> hashmap tables to connect the different data.
>
> Since I'm only ever operating on static data, I'm wondering if I can
> generate module files that capture the records as a sum type. To access the
> fields of the records, I could then imagine functions that exhaustively map
> the constructors to the data.
>
> Do any tools to generate .hs files from CSV or other formats exist? Insofar
> as this question has been asked before, the recommendation is "use Template
> Haskell", which makes sense, but is a less complete solution than I'm
> hoping for.
>
How does the TH hack below look?

See this Gist for this code and a test-case. Unfortunately there are a
few gotchas here,

  1. The record type needs a `Lift` instance[2]. There are a pain to
     write but can be derived[3]
  2. The type of your data can't be defined in the same module as the TH
     splice due to GHC's stage restriction

Cheers,

- Ben


[1] https://gist.github.com/bgamari/efad8560ab7dd38e9407
[2] 
http://hackage.haskell.org/package/template-haskell-2.9.0.0/docs/Language-Haskell-TH-Syntax.html#t:Lift
[3] http://hackage.haskell.org/package/th-lift


{-# LANGUAGE TemplateHaskell, FlexibleContexts #-}

module StaticCSV (staticCSV) where

import Control.Applicative
import Data.Csv as Csv hiding (Name)
import Data.Proxy
import Data.Data
import Language.Haskell.TH
import Language.Haskell.TH.Syntax (Lift, lift)
import qualified Data.ByteString.Lazy as BSL
import qualified Data.Vector as V

staticCSV :: (FromRecord a, Lift (V.Vector a)) => FilePath -> Proxy a -> ExpQ
staticCSV fileName ty = do
    contents <- runIO $ BSL.readFile fileName
    csv <- case decode NoHeader contents of
      Right a  -> return $ fmap (flip asProxyTypeOf ty) a
      Left err -> fail err
    [| csv |]

instance Lift a => Lift (V.Vector a) where
    lift v = do
        list <- ListE <$> mapM lift (V.toList v)
        return $ AppE (VarE 'V.fromList) list

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140530/a4154839/attachment-0001.sig>

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

Message: 4
Date: Fri, 30 May 2014 19:59:22 -0400
From: "Christian Espinoza L." <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Best way to have a fresh&updated Haskell
        installation
Message-ID:
        <CAGBwpM0D66=91w1t0aa9xu6gv-qg5wfs6xqv9d2-rs+jow8...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi guys, like subject says , how can I get it?
I'm using Debian Linux, and I need a guide to have a updated haskell
platform, easy to update when will necessary.

Haskell Platform is totally out of date, I know is required compile all,
but I need a guide in order to get a standard way.

Thanks in advance.
Christian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140530/693e29a1/attachment-0001.html>

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

Message: 5
Date: Fri, 30 May 2014 19:06:11 -0500
From: Christopher Allen <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Best way to have a fresh&updated
        Haskell installation
Message-ID:
        <cadnndootdquqradxfimaqki50vmtrpjleajwv0pofx79roa...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

My recommendation for Linux users is to use the Ubuntu PPA[1] if it's
compatible with your distro, otherwise binary distribution[2].

[1]: https://launchpad.net/~hvr/+archive/ghc
[2]: https://github.com/bitemyapp/learnhaskell#windows-and-other-linux-users


On Fri, May 30, 2014 at 6:59 PM, Christian Espinoza L. <[email protected]
> wrote:

> Hi guys, like subject says , how can I get it?
> I'm using Debian Linux, and I need a guide to have a updated haskell
> platform, easy to update when will necessary.
>
> Haskell Platform is totally out of date, I know is required compile all,
> but I need a guide in order to get a standard way.
>
> Thanks in advance.
> Christian.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140530/971f8638/attachment-0001.html>

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

Message: 6
Date: Sat, 31 May 2014 11:49:34 +0300
From: Ovidiu Deac <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] installing cabal 1.20 on linux mint
        debian edition (LMDE)
Message-ID:
        <CAKVsE7ts3WDwbx1Y7VYrHmvq=q--s2rDuipYzAe0=d+phrw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Eventually I fixed the problem by using the Trusty apt repository and then
let cabal update itself.

Thanks!


On Thu, May 29, 2014 at 11:06 PM, Dan Serban <[email protected]> wrote:

> What is the output of:
> ghc-pkg list | grep network
> ?
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140531/c789f462/attachment-0001.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 71, Issue 39
*****************************************

Reply via email to