Code Monkey home page Code Monkey logo

labels's Introduction

labels

Declare and access tuple fields with labels

$ git clone --recursive [email protected]:chrisdone/labels

The basic package

The labels package just provides labels and has very small source code and dependencies.

Some trivial examples provided by the labels package:

Get fields of a record
> get #bar (#foo := "hi", #bar := 123)
123
Set fields of a record
> set #bar 66 (#foo := "hi", #bar := 123)
(#foo := "hi",#bar := 66)

Note: You need GHC 8.0.1.

Integration with other packages

There are integration packages for getting labelled things out of common data parsers:

Data exploration package

I have put together a simple packge which brings together various packages around labels into one package:

labels's People

Contributors

chrisdone avatar jchia avatar nh2 avatar

Stargazers

Lautaro Emanuel avatar Артур Файзрахманов avatar Sohang Chopra avatar Compl Yue avatar Andreas Thoelke avatar Josh Burgess avatar larluo avatar Paulo Vicente avatar Wilton Lazary avatar clojj avatar abdul dakkak avatar Patrick Cieplak avatar Ben Booth avatar  avatar Sho Kohara avatar Miki Oracle avatar Hossein Abedi avatar Milán Nagy avatar  avatar Adam Wespiser avatar Ron Wolf avatar Matvey Aksenov avatar Daniel Mendler avatar  avatar  avatar YAMAMOTO Yuji avatar Mike Panciera avatar Romain Ruetschi avatar namhyunuk avatar Ollie Charles avatar Guido avatar Pascal Hartig avatar Qaiser Abbasi avatar Leon Di Stefano avatar Chris Parks avatar  avatar Homam Hosseini avatar Przemysław Kopański avatar Overmind Jiang avatar Cheng Shao avatar Maciej Bielecki avatar Matt Parsons avatar Alexander Biehl avatar Samuel Schlesinger avatar Tom Dimiduk avatar Yghor Kerscher avatar Jon Schoning avatar Mihai Maruseac avatar Charles Cooper avatar Austin Huang avatar Bjarke Vad Andersen avatar Konstantin Kirillov avatar Justin Le avatar Alexis Sellier avatar michaelt avatar Daniel Díaz Carrete avatar Daniel Kahlenberg avatar Andrew Darqui avatar Erik Rantapaa avatar Elliot Cameron avatar Alfredo Di Napoli avatar

Watchers

 avatar YAMAMOTO Yuji avatar Mihai Maruseac avatar James Cloos avatar Samuel Schlesinger avatar Robert Hardy avatar  avatar

labels's Issues

A Better Pandas

@chrisdone This is only tangentially to do with labels. I was trying to emulate http://tomaugspurger.github.io/modern-1.html in Haskell. Using his data set which is 113M, I thought I would start off by seeing what the headers are. I ran this in ghci:

main2 = do
  foo <- fmap decodeByName (LB.readFile "examples/787338586_T_ONTIME.csv")
  case foo of
    Right (header, rows :: Vector (Map String String)) -> do
      putStrLn $ show header
    Left err -> putStrLn err

This took a long time to run and used over 6G of memory eventually returning

*Main> main2
["FL_DATE","UNIQUE_CARRIER","AIRLINE_ID","TAIL_NUM","FL_NUM","ORIGIN_AIRPORT_ID","ORIGIN_AIRPORT_SEQ_ID","ORIGIN_CITY_MARKET_ID","ORIGIN","ORIGIN_CITY_NAME","ORIGIN_STATE_NM","DEST_AIRPORT_ID","DEST_AIRPORT_SEQ_ID","DEST_CITY_MARKET_ID","DEST","DEST_CITY_NAME","DEST_STATE_NM","CRS_DEP_TIME","DEP_TIME","DEP_DELAY","TAXI_OUT","WHEELS_OFF","WHEELS_ON","TAXI_IN","CRS_ARR_TIME","ARR_TIME","ARR_DELAY","CANCELLED","CANCELLATION_CODE","DIVERTED","DISTANCE","CARRIER_DELAY","WEATHER_DELAY","NAS_DELAY","SECURITY_DELAY","LATE_AIRCRAFT_DELAY",""]

Is there a better way of doing this? I'd quite like to write a Haskell equivalent of a pandas tutorial. Maybe we should create a separate repo for doing this and tracking how it is going.

Missleading note in the readme

Note: You need GHC 8.0.1 for the #foo syntax, otherwise you have to use $("foo") which works on GHC 7.10

The lower base bound for 0.2 is base >= 4.9, so GHC 7.10 is rulled out by that

how to rename a field name?

it can be implemented by add the new field name, and drop the old one.
but i want to know whether exist a more sensible way to do it

it seems the drop also can't be done directly, it need project's help

(:=) precedence

Currently, (:=) has a precedence of 6, which is too high if I want to do something like (#foo := x <$> y) because (<$>) has a precedence of only 4.

Is there any special reason the precedence of (:=) is not lower? Perhaps it should be 1?

The examples are very slow to execute on Ubuntu

The examples work and the code looks great, but the performance seems very poor.
Running
time stack exec labels-explore-example

gives on my laptop
flights distance
471949 3.7207249e8

real 0m54.148s
user 0m58.902s
sys 0m5.340s

.gitmodules URLs require GitHub account

The URLs in .gitmodule are of the form [email protected]:... instead of https://github.com/..., so git clone --recursive https://github.com/chrisdone/labels.git fails if the user has no GitHub account. To enable easy access, e.g. as part of an automated stack build using a robot user without any SSH key, the URLs in .gitmodule should be changed to the HTTPS form.

AFAIK, GitHub doesn't have any simple way to easily switch the view of the submodule URLs between HTTPS and SSH without changing the actual code of .gitmodule.

Generic instances?

How can I easily get Generic instances for the Labels 'record' types? Generic is needed for deriving instances like Hashable and ToJSON.

If it can't be done easily, I suppose a workaround easily getting instances of things like Hashable is to use Labels.reflect and GHC.Generics.from to extract the field names and values Rep? Is there a better way?

cabal install labels-explore.cabal fails with error ?

Hi there was trying to follow your post 'Working with data in Haskell' https://www.fpcomplete.com/blog/2016/09/data-haskell

So decided to pull the labels-master package down from here and went into each directory and did the following

cabal install labels.cabal (ran successfully to completion)
cabal install labels-cvs.cabal (ran successfully to completion)
cabal install labels-json.cabal (ran successfully to completion)
cabal install zip-conduit.cabal (ran successfully to completion)
cabal install http-client.cabal (ran successfully to completion)

when I ran cabal install labels-explore.cabal (It fails, doesn't complete, the log says the following is wrong)

root@haskellbox~/.cabal/logs# cat labels-explore-0.1.0.0.log


cabal: Entering directory '.'
Configuring labels-explore-0.1.0.0...
Building labels-explore-0.1.0.0...
Preprocessing library labels-explore-0.1.0.0...
[1 of 1] Compiling Labels.Explore ( src/Labels/Explore.hs, dist/build/Labels/Explore.o )

src/Labels/Explore.hs:26:5: error:
Ambiguous occurrence ‘.|’
It could refer to either ‘Data.Conduit..|’,
imported from ‘Data.Conduit’ at src/Labels/Explore.hs:72:1-29
or ‘Labels.Explore..|’, defined at src/Labels/Explore.hs:112:1
cabal: Leaving directory '.'


Can you help please would like to get this built so i can run the examples thank you

labels fails to build with GHC 8.2 RC3

I tried building labels with GHC 8.2 RC3 using this stack.yaml:

resolver: nightly-2017-07-20
compiler: ghc-8.2.0.20170704
compiler-check: match-exact
packages:
- labels

but got this error:

$ stack build labels
labels-0.3.2: build (lib)
Preprocessing library for labels-0.3.2..
Building library for labels-0.3.2..
[1 of 2] Compiling Labels.Internal  ( src/Labels/Internal.hs, .stack-work/dist/x86_64-linux/Cabal-2.0.0.0/build/Labels/Internal.o )

/home/jchia/gh/labels/labels/src/Labels/Internal.hs:66:5: error:
    • Couldn't match expected type ‘Proxy l'’
                  with actual type ‘p0 -> Proxy t0’
    • The equation(s) for ‘fromLabel’ have one argument,
      but its type ‘Proxy l'’ has none
      In the instance declaration for ‘IsLabel l (Proxy l')’
    • Relevant bindings include
        fromLabel :: Proxy l' (bound at src/Labels/Internal.hs:66:5)
   |
66 |     fromLabel _ = Proxy
   |     ^^^^^^^^^^^^^^^^^^^

--  While building package labels-0.3.2 using:
      /home/jchia/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.0.0.0_ghc-8.2.0.20170704 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.0.0.0 build lib:labels --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

I suspect it's because of GHC 8.2 changes to OverloadedLabels.

(labels-json) 'Maybe' doesn't make the field optional

Unlike aeson's TH and Generics-derived instances, Maybe is not special cased by labels-json.

> data Foo = Foo { foo :: Maybe Int } deriving (Show, Generic, FromJSON)
> decode "{}" :: Maybe Foo
Foo { foo = Nothing }
> decode "{}" :: Maybe ("foo" := Maybe Int)
Nothing

how to merge two label record?

currently i only can find cons function to expand record.
it's possible to merge two label record, and merge the same field?

*Main Labels> get #b (#a := 3, #b := "c", #a:="d")
"c"
*Main Labels> cons (#a := "d") (#a := 3)
(#a := "d",#a := 3)
*Main Labels> get #a (#a := 3, #b := "c", #a:="d")

<interactive>:65:1: error:
    • Overlapping instances for Has
                                  "a" value ("a" := value, "b" := value0, "a" := value)
      Matching givens (or their superclasses):
        Has "a" value ("a" := value, "b" := value1, "a" := value)
          bound by the inferred type for ‘it’:
                     forall value value1.
                     (Num value,
                      Has "a" value ("a" := value, "b" := value1, "a" := value),
                      Data.String.IsString value1, Data.String.IsString value) =>
                     value
          at <interactive>:65:1-36
      Matching instances:
        instance Has l a (l := a, u2, u3) -- Defined in ‘Labels.Internal’
        instance Has l a (u1, u2, l := a) -- Defined in ‘Labels.Internal’
    • In the ambiguity check for the inferred type for ‘it’
      To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
      When checking the inferred type
        it :: forall value1 value2.
              (Num value1,
               Has "a" value1 ("a" := value1, "b" := value2, "a" := value1),
               Data.String.IsString value2, Data.String.IsString value1) =>
              value1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.