tag:blogger.com,1999:blog-1777990983847811806.post3922838312193082443..comments2024-03-16T16:29:29.582-07:00Comments on Haskell for all: Auto-generate a command line interface from a data typeGabriella Gonzalezhttp://www.blogger.com/profile/01917800488530923694noreply@blogger.comBlogger17125tag:blogger.com,1999:blog-1777990983847811806.post-77847513095853520292016-12-30T06:29:28.112-08:002016-12-30T06:29:28.112-08:00I didn't have any plans to add this, but if yo...I didn't have any plans to add this, but if you think there is a reasonable way to do this then you can open up an issue to discuss this in more detailGabriella Gonzalezhttps://www.blogger.com/profile/01917800488530923694noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-74062753862193980542016-12-27T06:03:51.372-08:002016-12-27T06:03:51.372-08:00Amazing!
Any plans on adding support for records ...Amazing!<br /><br />Any plans on adding support for records whose fields are other records?Damianhttps://www.blogger.com/profile/12880789608369397377noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-61566693151955598352016-03-12T00:18:39.625-08:002016-03-12T00:18:39.625-08:00Certainly can! On my way :DCertainly can! On my way :Datchttps://www.blogger.com/profile/02162675473274370201noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-38363240368018609092016-03-11T14:19:29.127-08:002016-03-11T14:19:29.127-08:00Could you open up an issue for this here: https://...Could you open up an issue for this here: https://github.com/Gabriel439/Haskell-Optparse-Generic-Library/issuesGabriella Gonzalezhttps://www.blogger.com/profile/01917800488530923694noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-92067001220227394882016-03-11T12:57:11.681-08:002016-03-11T12:57:11.681-08:00Love the simplicity of this! Nice work as always.
...Love the simplicity of this! Nice work as always.<br /><br />Can this be used with stack? When I run the binary built from a `stack install` I just get a "bad value of -N" error and then a list of opts for the GHC runtime...atchttps://www.blogger.com/profile/02162675473274370201noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-29963876856628010112016-03-01T17:26:05.358-08:002016-03-01T17:26:05.358-08:00So in the case of `Enum` the user can always opt i...So in the case of `Enum` the user can always opt in to the version that you describe by deferring to the `ParseFields` instance like this:<br /><br /> instance ParseRecord MyEnum where<br /> parseRecord = fmap getOnly parseFieldsGabriella Gonzalezhttps://www.blogger.com/profile/01917800488530923694noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-85473820613025359602016-02-29T08:48:34.830-08:002016-02-29T08:48:34.830-08:00One more thing, on the Parser specific case: you ...One more thing, on the Parser specific case: you might want to do something specific for the Enum (or Enum and Ord and Bounded) case. You likely don't want a command there so much as a set of single flag options. But YMMV.adamCShttps://www.blogger.com/profile/01687874586058631208noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-18918688171411799572016-02-28T19:26:53.938-08:002016-02-28T19:26:53.938-08:00I remember now why Alternative didn't work for...I remember now why Alternative didn't work for me. I am interested in cases where I need all the alternatives before I can choose (e.g., turning the choice among constructors of a sum type into a dropdown in an HTML form). But to use alternative I need to combine them pair wise, right? I couldn't see how that would work for me.<br /><br />AdamadamCShttps://www.blogger.com/profile/01687874586058631208noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-65202784546736511772016-02-28T19:00:23.368-08:002016-02-28T19:00:23.368-08:00Yeah. I thought about alternative but I wasn't...Yeah. I thought about alternative but I wasn't sure I could embed the metadata (and maybe configuration info) I wanted to pass around into it.<br /><br />But I'll look again!<br /><br />And of course release what you think is useful! I look forward to seeing the design more fully.<br /><br />AdamadamCShttps://www.blogger.com/profile/01687874586058631208noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-17266177428838272482016-02-28T17:57:06.574-08:002016-02-28T17:57:06.574-08:00Note that an `Applicative` with a method to handle...Note that an `Applicative` with a method to handle sum types is Haskell's `Alternative` class. A typical idiom for using `Alternative` to combine multiple value is:<br /><br /> data Example = C1 T1 | C2 T2 | C3 | T3<br /><br /> instance Alternative F<br /><br /> v1 :: F T1<br /> v2 :: F T2<br /> v3 :: F T3<br /><br /> v :: F Example<br /> v = fmap C1 v1 <|> fmap C2 v2 <|> fmap C3 v3<br /><br />I agree that once you have some type constructor `F` that implements `Alternative` you should be able to derive some way to mix that with a `Generic` instance in a uniform way.<br /><br />One way you might provide a uniform interface is to do something like this:<br /><br /> class Uniform a where<br /> auto :: Alternative f => f a<br /><br /> instance (Uniform a, Uniform b) => Uniform (a, b) where<br /> auto = liftA2 (,) auto auto<br /><br /> instance (Uniform a, Uniform b) => Uniform (Either a b) where<br /> auto = fmap Left auto <|> fmap Right auto<br /><br /> instance Uniform Void where<br /> auto = empty<br /><br /> instance Uniform () where<br /> auto = pure ()<br /><br />... and then given any type that implements `Generic` you can automatically derive a `Uniform` instance for the same type. Then you just instantiate the `f` to your specific `Alternative` type and you are done.<br /><br />Would you mind if I release something like the above as a new package?Gabriella Gonzalezhttps://www.blogger.com/profile/01917800488530923694noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-4240894218061306262016-02-28T17:22:47.121-08:002016-02-28T17:22:47.121-08:00This is cool! I did something similar (just a wee...This is cool! I did something similar (just a week ago!) but with TH, and fewer features. I was hoping to re-implement with Generics but was stuck so I will look to your work for hints.<br /><br />My idea was also more general: to build lots of things from a data type. My original plan was an HTML form for an FRP library. But then I realized that as long as the thing you use to build each type is applicative plus a method to handle sum-types, you can make a fairly general builder.<br /><br />My idea so far is here: https://github.com/adamConnerSax/dataBuilder<br /><br />Have you thought about making the infrastructure more general? It seems like it would have a few applications--any kind of user input really: html forms, command line, etc. <br /><br />It also starts to seem sort of lensish though I can't make that analogy precise. <br /><br />Anyway, cool work!<br /><br />Adam<br />adamCShttps://www.blogger.com/profile/01687874586058631208noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-4349840125847554792016-02-28T17:10:06.989-08:002016-02-28T17:10:06.989-08:00This is cool! I did something similar (just a wee...This is cool! I did something similar (just a week ago!) but with TH, and fewer features. I was hoping to re-implement with Generics but was stuck so I will look to your work for hints.<br /><br />My idea was also more general: to build lots of things from a data type. My original plan was an HTML form for an FRP library. But then I realized that as long as the thing you use to build each type is applicative plus a method to handle sum-types, you can make a fairly general builder.<br /><br />My idea so far is here: https://github.com/adamConnerSax/dataBuilder<br /><br />Have you thought about making the infrastructure more general? It seems like it would have a few applications--any kind of user input really: html forms, command line, etc. <br /><br />It also starts to seem sort of lensish though I can't make that analogy precise. <br /><br />Anyway, cool work!<br /><br />Adam<br />adamCShttps://www.blogger.com/profile/01687874586058631208noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-71025825133176686082016-02-28T14:21:19.750-08:002016-02-28T14:21:19.750-08:00Yeah, that does look pretty similar. After studyi...Yeah, that does look pretty similar. After studying it a bit, I think I can summarize the main differences as:<br /><br />* `optparse-generic` produces `Parser`s compatible with the `optparse-applicative` library<br />* `optparse-generic` supports sum types<br />* `optparse-generic` has instances for more types (particularly `Char`, which is tricky to do without conflicting with `String`)<br />* `getopt-generics` lets you combine records using tuples<br />* `getopt-generics` lets you add help information and short flags with the `Modifiers` featureGabriella Gonzalezhttps://www.blogger.com/profile/01917800488530923694noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-46689588067419409712016-02-28T14:00:26.110-08:002016-02-28T14:00:26.110-08:00Yeah, this is mostly intended as a way to quickly ...Yeah, this is mostly intended as a way to quickly bind Haskell code to a command-line interface. However, I'm looking into ways to add help textGabriella Gonzalezhttps://www.blogger.com/profile/01917800488530923694noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-39979505584092070292016-02-28T10:28:15.870-08:002016-02-28T10:28:15.870-08:00Wtf are Kmett or Snoyman doing in that rant? :(Wtf are Kmett or Snoyman doing in that rant? :(Anonymoushttps://www.blogger.com/profile/06180476773002153033noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-83777030210825228192016-02-28T05:54:28.128-08:002016-02-28T05:54:28.128-08:00I love you Gabriel! You know what I need. Unlike E...I love you Gabriel! You know what I need. Unlike Edward Kmett or Michael Snoyman.<br /> <br />But this approach has a lot of restrictions: no short keys, no options, no explanation to the keys and commands. I think it is possible to fix with the help of type-level string literals. Also it creates insoluble problems with internalization.nikita_timofeevhttps://www.blogger.com/profile/11463976387928175723noreply@blogger.comtag:blogger.com,1999:blog-1777990983847811806.post-37582699377060542362016-02-28T05:04:44.712-08:002016-02-28T05:04:44.712-08:00This library is similar, even though it has less f...This library is similar, even though it has less features and it seems incomplete https://github.com/soenkehahn/getopt-genericsfrancescohttps://www.blogger.com/profile/05584516744763422667noreply@blogger.com