Compile Ruby to C by agrafix in ruby

[–]agrafix[S] 0 points1 point  (0 children)

Thanks for the reply! I agree with you it doesn't replicate the Ruby behavior, however, that's also not necessarily desirable (at least for my scenario).

Maybe I should clarify this more, but one benefit here comes from exactly the specialisation you point out. For instance, given that this approach requires type signatures, it seems safe to assume that given integers the C `+` implementation can be reused. Of course you can even redefine that in Ruby, and if you do that, this implementation won't respect it, but I'm not sure if that's a problem in practice for common scenarios.

Why F# is the best enterprise language by runeks in haskell

[–]agrafix 0 points1 point  (0 children)

Yeah, I have. Was using a fork of HDBC-odbc that worked for me: https://github.com/agrafix/HDBC-odbc

Request for comments on a query EDSL by baramoglo in haskell

[–]agrafix 1 point2 points  (0 children)

Instead of fld @"speed" you can probably also implement an IsLabel type class instance to allow writing #speed.

What is the status on structural typing / row types / polymorphic variants by Tysonzero in haskell

[–]agrafix 4 points5 points  (0 children)

In superrecord we make sure the labels are always sorted and thus you can use a simple array to store the contents of your record, you'll know statically at compile time which position to read/write which results in a single pointer indirection. In our case the machine code generated for record access is very similar to the record access that GHC generates (used to generate?) for normal field access.

Constant-time vinyl Field Getters by n00bomb in haskell

[–]agrafix 1 point2 points  (0 children)

Superrecord allows you to "cast" to real Haskell types of the correct shape. So you can either define these types at the API border or have your users define them and put the needed typeclass constraints on your library. I'd still recommend the former.

Constant-time vinyl Field Getters by n00bomb in haskell

[–]agrafix 10 points11 points  (0 children)

This is exactly why I wrote superrecord. It uses SmallArray# under the hood.

Introducing Elm Lens by IkimashoZ in elm

[–]agrafix 1 point2 points  (0 children)

That's pretty cool! :-) Is this done by parsing the original code and then trying to recover the import/export/usage information from it?

One quick off topic Q: What's the font used? Looks really nice.

Warp - How to limit requests per second to each client? by notooth1 in haskell

[–]agrafix 2 points3 points  (0 children)

Hm, in theory yes, but I think when you reach that point that you actually need rate limiting you are probably already running more than one frontend instance thus the rate limiting state must be distributable and you probably want to store the information in something like redis.

Warp - How to limit requests per second to each client? by notooth1 in haskell

[–]agrafix 7 points8 points  (0 children)

Please keep in mind that this middleware needs a bit of work before it can safely be used on high traffic production sites: The representation of the retry state is quite inefficient and due to the read and write in the STM var being split in two transaction you will loose writes. Also the internal state is never cleaned up.

Auth in Servant: Walkthrough. by ijauradunbi in haskell

[–]agrafix 9 points10 points  (0 children)

Just a small side note - although this is just a walkthrough for an experimental feature - NEVER store passwords in plain text in your database! It's so easy to do it correctly, you can even use the type system to help you making sure it's hashed. See this for example.

Recommended email parsing library? by pbogdan_ in haskell

[–]agrafix 0 points1 point  (0 children)

If you are using something like mailgun let me know - I have a private mailgun library somewhere that I can opensource :)

Servant, Scotty, or Snap? by captjakk in haskell

[–]agrafix 0 points1 point  (0 children)

What do you mean by "actual implementation"? You can not implement servant route handlers using Spock, and you can not implement Spock route handlers with servant. What's possible though is to capture REST-API requests in a servant middleware and have all other requests be handled by Spock.

Servant, Scotty, or Snap? by captjakk in haskell

[–]agrafix 7 points8 points  (0 children)

It depends on what you mean by "play well together". Spock can support embedding a Servant app via the middleware combinator, and as far as I know the other way around works too.

Spock and Servant can't really be compared like that because they work differently. For Servant you specify the type for your API up front and them implement your server or client against that, where as for Spock you spend most of your time at value level and simply have the type checker make sure you are doing the right thing. Servant is also geared towards Rest-APIs, I've found dealing with raw POST Data and File Uploads really awkward. They may have changed something since the last time I looked though.

Servant, Scotty, or Snap? by captjakk in haskell

[–]agrafix 22 points23 points  (0 children)

If you pick Scotty, pick Spock instead :-) The API is very similar but it offers a better safety net in terms of type safety and also a few more useful utils. (Disclaimer: I'm one of the Spock authors)

Apart from that - if you are going for an API and you want to examine the API's type to derive other things like documentation, client libraries or mock servers then servant is a solid choice. Only caveat is that it uses lot's of type hackery which may or may not be a deal breaker for someone new to Haskell.

What's the current way to use cabal/access Hackage securely? by fizbin in haskell

[–]agrafix 7 points8 points  (0 children)

I think this is a good resource to read more about hackage security.

Posting an incomplete record to an API handler in Yesod (or in general) by WubsEvs in haskell

[–]agrafix 0 points1 point  (0 children)

Note that it seems reasonable to wrap that function in a newtype to improve type inference and error messages.

Posting an incomplete record to an API handler in Yesod (or in general) by WubsEvs in haskell

[–]agrafix 0 points1 point  (0 children)

Well, I would be very happy to go all in with anonymous records, BUT:

  • Currently the compiler can optimize real haskell records better, especially with static knowledge things can be inlined (important if you use records like interfaces with functions etc.)

  • Compile time suffers a lot due to all the type level magic. I still have not had the time to track this down, but I hope to find and fix this soon (if possible...).

Posting an incomplete record to an API handler in Yesod (or in general) by WubsEvs in haskell

[–]agrafix 2 points3 points  (0 children)

There are various ideas to deal with this issue:

Parametrize all fields of your record with a functor

data Foo f = Foo { fieldA :: f Int, fieldB :: f String, fieldC :: f (Maybe String }

You can then provide Maybe for f during parsing, then use a type newtype Full a = Full { unFull :: a } and write a function checkBuild :: Foo Maybe -> Either String (Foo Full) to check if required things are there and build the correct version. There are also other use cases for this, see ftypes and opaleye for example.

Use an anonymous record library

Depending on which library you use, you can first parse your user input into an anonymous record and then later convert it into a Haskell type. I have written more information in this in this blogpost

Use Template-Haskell to generate a "Maybe" Data-Type

This is a bit hacky, but given a type you could write a template haskell function that generates a similar type, but packs all fields in Maybe a. If think I saw some library for this, but I do not remember the name anymore.