Code Monkey home page Code Monkey logo

barbies-th's Introduction

Twitter: @fumieval

Haskell

Name Stars Issues Merge Requests Status Hackage
barbies-th Stars Issues PRs CI Hackage
bindings-portaudio Stars Issues PRs CI Hackage
data-vector-growable Stars Issues PRs CI Hackage
deriving-aeson Stars Issues PRs CI Hackage
discord-vc-notification Stars Issues PRs CI Hackage
extensible Stars Issues PRs CI Hackage
incremental Stars Issues PRs CI Hackage
mason Stars Issues PRs CI Hackage
membership Stars Issues PRs CI Hackage
monad-skeleton Stars Issues PRs CI Hackage
objective Stars Issues PRs CI Hackage
tangle Stars Issues PRs CI Hackage
tehepero Stars Issues PRs CI Hackage
webauthn Stars Issues PRs CI Hackage
winery Stars Issues PRs CI Hackage
witherable Stars Issues PRs CI Hackage

barbies-th's People

Contributors

expipiplus1 avatar fumieval avatar gergoerdi avatar jackkelly-bellroy avatar kakkun61 avatar peterwicksstringfield avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

barbies-th's Issues

Derive Show, Eq, ...

I have problems deriving Show and Eq instances for a data class when following the instructions here: https://github.com/fumieval/barbies-th?tab=readme-ov-file#deriving-pass-through

I added these two test cases to the test suite of barbies-th and they also fail to come up with the according instances.

test_show :: String
test_show = show test_con

test_eql :: Bool
test_eql = test_con == test_con

Do I have a problem understanding how to derive the instances with barbies-th or is the functionality broken at the moment?

Feature request: lift derived instances `via Barbie`

Currently, if I want to use Barbies-TH to create a HKD that has per-field Semigroup and Monoid instances, I can do it like so:

declareBareB [d|
  data CPUOut = CPUOut
      { progAddr :: PC
      , memAddr :: Ptr
      , memWrite :: Maybe Cell
      , output :: Maybe Cell
      , inputNeeded :: Bool
      }|]
deriving via Barbie (CPUOut Covered) f instance (forall a. Semigroup (f a)) => Semigroup (CPUOut Covered f)
deriving via Barbie (CPUOut Covered) f instance (forall a. Monoid (f a)) => Monoid (CPUOut Covered f)

Would it be possible to automate this / hide the deriving via magic, and allow the user to instead write

declareBareB [d|
  data CPUOut = CPUOut
      { progAddr :: PC
      , memAddr :: Ptr
      , memWrite :: Maybe Cell
      , output :: Maybe Cell
      , inputNeeded :: Bool
      }
      deriving (Semigroup, Monoid)|]

which would generate the same code as above?

incompatible with record fields that are actually duplicated -- "symbol already defined"

barbies-th works fine with DuplicateRecordFields enabled (thanks to the name unmangling patches); but it can't handle record fields that are actually duplicated. Possibly this is an accepted limitation, but it would be nice to document it I think. The error message is not very friendly:

... Assembler messages: ... Error: symbol `testlibzm0zi1zi0zi0zminplace_Lib_qux_info' is already defined ... testlibzm0zi1zi0zi0zminplace_Lib_qux_info

@Elvecent reported this as well, at the bottom of the thread in #3.

GHC 8.10.7
barbies == 2.0.3.1
barbies-th == 0.1.10

Example:

{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DuplicateRecordFields #-}

module Lib where

import Barbies.TH (declareBareB)

declareBareB
  [d|
    data Foo = Foo
      { qux :: Integer
      }
    |]

declareBareB
  [d|
    data Bar = Bar
      { qux :: Integer
      }
    |]
cabal-version:   3.4
name:            testlib
version:         0.1.0.0
build-type:      Simple

common warnings
    ghc-options: -Wall

library
    import:           warnings
    exposed-modules:  Lib
    build-depends:
        base ^>=4.14.3.0,
        barbies == 2.0.3.1,
        barbies-th == 0.1.10
    hs-source-dirs:   src
    default-language: Haskell2010
peter@gtower:~/2022october8_reproduce_barbies_error$ cabal build
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
 - testlib-0.1.0.0 (lib) (first run)
Preprocessing library for testlib-0.1.0.0..
Building library for testlib-0.1.0.0..
[1 of 1] Compiling Lib              ( src/Lib.hs, /home/peter/2022october8_reproduce_barbies_error/dist-newstyle/build/x86_64-linux/ghc-8.10.7/testlib-0.1.0.0/build/Lib.o, /home/peter/2022october8_reproduce_barbies_error/dist-newstyle/build/x86_64-linux/ghc-8.10.7/testlib-0.1.0.0/build/Lib.dyn_o )
/tmp/ghc80775_0/ghc_2.s: Assembler messages:

/tmp/ghc80775_0/ghc_2.s:1298:0: error:
     Error: symbol `testlibzm0zi1zi0zi0zminplace_Lib_qux_info' is already defined
     |
1298 | testlibzm0zi1zi0zi0zminplace_Lib_qux_info:
     | ^

/tmp/ghc80775_0/ghc_2.s:1329:0: error:
     Error: symbol `testlibzm0zi1zi0zi0zminplace_Lib_qux_closure' is already defined
     |
1329 | testlibzm0zi1zi0zi0zminplace_Lib_qux_closure:
     | ^
`gcc' failed in phase `Assembler'. (Exit code: 1)

I tried to minimize the testcase further by expanding the splices and minimizing the generated code, but I was unable to achieve further minimization. I expanded one splice using the code-action offered by HLS. I found that the generated code is referencing a symbol called (Unit :: (Type -> Constraint) -> Type -> Constraint). I stubbed out such a type like this:

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE UndecidableSuperClasses #-}
import Data.Kind (Constraint, Type)
class c t => Unit (c :: Type -> Constraint) (t :: Type) where
  {- empty body -}

When I added that bit, the generated code started compiling. That is, without the "symbol already defined" error.

Thanks for the library, seems cool.

matroska barbies

It would be nice to be able to do something like this:

declareBareB [d|
  data Foo = Foo { foo :: Int }
  data Bar = Bar { bar :: Foo }
  |]

And have both Foo and Bar become barbies, with Foo inheriting the clothing style form Bar

Doesn't work if `DuplicateRecordFields` is turned on

Example source illustrating the problem:

{-# LANGUAGE TemplateHaskell, FlexibleInstances, DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
import Barbies
import Data.Barbie.TH

declareBareB [d|
  data R = MkR
      { foo :: Int
      } |]

This fails with:

src/Foo.hs:6:1: error:
    Illegal variable name: ‘$sel:foo:MkR’
    When splicing a TH declaration:
      data R_0 sw_1 h_2
    = MkR_3 {$sel:foo:MkR_4 :: (Barbies.Internal.Wear.Wear sw_1
                                                           h_2
                                                           GHC.Types.Int)}
    deriving GHC.Generics.Generic
  |
6 | declareBareB [d|
  | ^^^^^^^^^^^^^^^^...

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.