News aggregator

pattern matching v. type checking

haskell-cafe - Sun, 01/10/2016 - 10:09am
I am, thanks to an idea from Elliot Cameron, using the Functional Graph Library (FGL) to implement [1] something resembling a hyperggraph, which I'm calling Mindmap, in which relationships can involve any number of things, including other relationships. (By contrast, in a graph, Edges cannot belong to other Edges; only Nodes can.) Here are the types: -- Exprs (expressions) play Roles in Rels (relationships). -- A k-ary (Arity k) Rel consists of a k-ary template and k members. -- Each k-ary Rel emits k+1 Edges toward the other Exprs: -- one connects it to its RelTplt (relationship template) -- k more connect it to each of its k RelMbrs (relationship members) -- The two paragraphs after it will clear up any questions about the next. type Mindmap = Gr Expr Role data Role = RelTplt | RelMbr RelPos deriving (Show,Read,Eq,Ord) data Expr = Str String | Tplt Arity [String] | Rel Arity -- TODO ? deduce the Arity of a Tplt from its [String] -- TODO ? deduc
Categories: Offsite Discussion

Help with pcre-heavy

Haskell on Reddit - Sun, 01/10/2016 - 9:38am

I have this code:

{-# LANGUAGE QuasiQuotes #-} import Text.Regex.PCRE.Heavy (gsub, re) ignore_comments :: String -> String ignore_comments text = gsub [re|\/\*[^\*]\*\/|] "" text main = do print $ ignore_comments "/*test commentary*/ other test"

He is cut simple commentary from string. But he doesn't work on test string(prints all string, without changes). I understand this is due to the initial slash in regexp. Maybe exist advanced option or escape rule for this? What's my mistake?

submitted by xolcman
[link] [13 comments]
Categories: Incoming News

EndoApplicatives, anything similar?

Haskell on Reddit - Sun, 01/10/2016 - 9:34am

I've got this typeclass here (EDIT: It's a MonoApplicative, not an EndoApplicative):

class Functor f => MonoApplicative f where pureM :: a -> f a (<#>) :: f (a -> a) -> f a -> f a

It's exactly like Applicative, but restricting <*> to a single type. I tried to find something similar in the ecosystem, is there something out there?

submitted by AisRauli
[link] [31 comments]
Categories: Incoming News

Promotion of field accessors using DataKinds

haskell-cafe - Sun, 01/10/2016 - 1:23am
Hello all, Let's say I have some data data Config = Conf (len :: Nat) (turboEncabulate :: Bool) Using DataKinds, we can promote Config to a kind and Conf to a type. However, it does not appear that GHC supports e.g. data Thing (conf :: Config) = Thing data Count (n :: Nat) = Count foo :: Thing conf -> Count (len conf) foo Thing = Count That is, it does not appear to properly replace "len conf" with the value of len from conf. Instead, the way I've found to do this is to define class Lengthed (a :: Config) where type Len a :: Nat instance Lengthed (Conf n) where type Len (Conf n t) = n Now, foo :: Thing conf -> Count (Len conf) works fine. So manually defining a type function that intuitively does the exact same thing as "len" seems to work. Is there a particular reason behind this? Thanks, Will _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-
Categories: Offsite Discussion

Recent Spam

Haskell on Reddit - Sun, 01/10/2016 - 1:20am

Most of you have probably seen some intermittent spam, I just finished overhauling automod to hopefully curtail it more quickly than it has been. Please -- if you continue to see this spam -- report it and send me a modmail. Reporting it as 'spam' helps train the reddit spam filter, afaik, and modmailing us helps surface things we might miss.

All of reddit is currently getting pelted by some spam ring, hopefully it lets up soon.

EDIT: (because I forgot) -- part of this will automatically remove posts from users that are less than a few days old. If you are new, I understand this may be inconvenient, but it is necessary for the overall health of the community. If you have something you want to post and can't, wait a day. If you can't wait, send a modmail and we'll see what we can do.

submitted by jfredett
[link] [5 comments]
Categories: Incoming News

suppress warning "Defined but not used: type variable ‘x’" in GHC-8.0

glasgow-user - Sun, 01/10/2016 - 12:57am
GHC-8.0 emits several new warnings of this kind: Defined but not used: type variable ‘x’ for declarations like type instance Snd x y = y Enthusiastically, I started to replace unused type function arguments by underscores, only to find out that older GHC versions do not accept that. With what option can I disable this warning? Or can it be removed from -Wall for now?_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
Categories: Offsite Discussion

Adding writer transformer to list monad.

Haskell on Reddit - Sun, 01/10/2016 - 12:57am

Hello, As an exercise, I was trying to write a function that calculates all combinations of given list. So when I call the function like this

combinations [1,2,3]

It would return following value:

[[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]]

So, first I implemented a classic recursive version of the function. Than I implemented another one that is using list monads.

After I have 2 versions of the same function, I wanted to add writer monad to them to log function calls.

I was able to add writer monad to plain version, but I could not do the same thing for the one that uses list monad.

In short, I could not use writer monad transformer. Can somebody go over my function and tell me how to add writer monad transformer to that function?

Here is the all the functions I implemented:

http://nbviewer.ipython.org/gist/huseyinyilmaz/752a792bdc646af1eaba#Combinations-with-list-monad-and-writer-transformer

submitted by yilmazhuseyin
[link] [7 comments]
Categories: Incoming News

How to make industry quality software with Haskell?

Haskell on Reddit - Sun, 01/10/2016 - 12:51am

I have only used Haskell in academia where I just run my files using ghc and show my professors the output. Although, now I am looking to start a project with Haskell and I was wondering what are some tools I should be using when developing my project? In conjunction with that I am concerned about directory architecture and I am not sure what the best practice is for Haskell projects, perhaps there is a guide out there.

submitted by lilred181
[link] [34 comments]
Categories: Incoming News

Regarding Developing my skills with haskell!

haskell-cafe - Sat, 01/09/2016 - 8:50pm
Hello, I want to learn some practical application using haskell like some projects or developing a game. Can anyone suggest me some link to develop my skills with haskell ? Cheers, Abhijit _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Douglas M. Auclair (geophf): December 2015 1HaskellADay Problems and Solutions

Planet Haskell - Sat, 01/09/2016 - 3:17pm
December 2015
  • December 30th, 2015: For today's #haskell problem we convert valid airport IATA codes to ints and back http://lpaste.net/9126537884587786240 And a Happy New Year solution: http://lpaste.net/2748656525433110528 Safe travels should you be Haskelling by air!
  • December 28th, 2015: So, remember ADVENT? What happens when your INV becomes full? Today's #haskell problem looks at that http://lpaste.net/5153847668711096320
  • December 23rd, 2015: Warm and fuzzy December, so we have a warm and fuzzy #haskell problem for today http://lpaste.net/6855091060834566144
  • December 21st, 2015: For today's #haskell problem we are to deduce stock splits using LOGIC and SCIENCE http://lpaste.net/7920293407518359552
  • December 18th, 2015: Today's #haskell problem... 'may' be thematic with that 'Star ...' what was the name of that movie? http://lpaste.net/7186856307830292480 Gosh! Star ... something! eh, whatevs: just let the Wookie win (always the best policy) http://lpaste.net/4229765238565634048 
  • December 17th, 2015: For today's #haskell problem we look at reporting out periodically on an investment and, BONUS! charting it! http://lpaste.net/638111979885559808 And we've charted our AAPL investment growth, too! http://lpaste.net/5472780506909114368 
  • December 16th, 2015: For (coming onto) today's #haskell problem we demask the masked data to unmaskify it, yo! http://lpaste.net/3793517022239784960 And then the solution unmasked that masked data! (that's convenient.) http://lpaste.net/5286190256939335680
  • December 15th, 2015: So yesterday we masked some rows, but what happened to the masking dictionary? Today's #haskell problem we save it http://lpaste.net/7703498271758483456 Ah! So that's where that cipher went! http://lpaste.net/2548817005729808384
  • December 14th, 2015: We look at a way of masking data for today's #haskell problem http://lpaste.net/4428582328419221504 And the solution gives us some lovely masked rows http://lpaste.net/7169250386480463872
  • December 11th, 2015: Today's #haskell problem asks: WHAT DOES THE TRANSFORMED JSON SAY! http://lpaste.net/5253460432890363904 (okay, that was weaksauce)
  • December 10th, 2015: For today's #Haskell problem we try to find relevancy in our daily lives http://lpaste.net/4994238781251911680 ...well, in #JSON, which is the same thing.
  • December 9th, 2015: Today's #haskell problem asks you to read in some rows of #JSON http://lpaste.net/3949063995918385152 We'll be looking into this data set through the week "Watcha readin'?" "JSON." "Cool! ... No, ... wait." http://lpaste.net/218583096285462528
  • December 8th, 2015: My main man, magic Mike (m^5 to his friends) said: "You're doing it wrong."Do it right for today's #haskell problem http://lpaste.net/6186236014281883648 A first stab at the solution, not taking into account splits, is posted at http://lpaste.net/6854975053767901184 And the split-adjusted solution here: http://lpaste.net/2656933684896071680 ~3700%-gain. It's time for me to sing the "You're the Top"-song to @MacNN_Mike
  • December 7th, 2015: In today's #haskell problem we cry «On y va!» and have at it! http://lpaste.net/5243343693259210752 En garde, you pesky investment problem, you! The solution shows Dr. Evil does NOT get ONE MILLION DOLLARS! http://lpaste.net/177540921380831232 Nor piranhas with laser beams on their heads, either.
  • December 4th, 2015: We write a web-proxy to help out poor, little Ajax go cross domain for today's #haskell problem http://lpaste.net/5120963316033781760
  • December 3rd, 2015: We meet the Ip-man for today's #haskell problem. Hiya! http://lpaste.net/8926203451507998720 Today's solution shares a little-known fact http://lpaste.net/5525895581479731200 AND ALSO uses <$> as well! Is there a weekly limit on these thingies?
  • December 2nd, 2015: Synthetic data generation for today's #haskell problem http://lpaste.net/4208367754446635008 NOT ONLY did we write a Synthetic data generator in a day http://lpaste.net/6059310371951345664 but we learned all 50 states AND used <$> and <*> – BONUS!
  • December 1st, 2015: In today's #haskell problem, we see @geophf lose his cool. http://lpaste.net/6645397898311761920 No... wait... That's not news now, is it. (RID analysis). Unwordin' down-low on the arrr-eye-dee, LIKE A GANGSTA! http://lpaste.net/7371239202307964928
Categories: Offsite Blogs

CfP: Workshop on Program Transformation for Programmability in Heterogeneous Architectures (Co-located with CGO16); Deadline Jan 15

General haskell list - Sat, 01/09/2016 - 2:02pm
[Apologies if you receive multiple copies of this announcement.] ********************************************************************************* PROHA 2016, CALL FOR PAPERS First Workshop on Program Transformation for Programmability in Heterogeneous Architectures http://goo.gl/RzGbzY Barcelona, 12th March 2016, in conjunction with the CGO'16 Conference ********************************************************************************* Important Dates: Paper submission deadline: 15 January 2016 23:59 (UTC) Author notification: 5 February 2016 Final manuscript due: 26 February 2016 Scope: Developing and maintaining high-performance applications and libraries for heterogeneous architectures is a difficult task, usually requiring code transformations performed by an expert. Tools assisting in and, if possible, automating such transformations are of course of great interest. However, such tools require significant knowledge and reasoning capabilities. For example, the former could be a machine-unders
Categories: Incoming News

Telegram Bot API bindings

Haskell on Reddit - Sat, 01/09/2016 - 11:35am

High-level bindings to the Telegram Bots API based on servant library.

telegram-api library is published on hackage.

Version 0.2.1.0 has the following features:

  • Both getUpdates request and webhook can be used to receive updates for your bot (mutually exclusive).
  • New Inline mode
  • Custom keyboards
  • Permissive BSD3 license

To be added:

  • Uploading photos, videos, etc

Example of getMe request:

import Control.Monad import qualified Data.Text.IO as T import Data.Maybe import Web.Telegram.API.Bot main :: IO () main = do Right GetMeResponse { user_result = u } <- getMe token T.putStrLn (user_first_name u) where token = Token "bot<token>" -- entire Token should be bot123456:ABC-DEF1234ghIkl-zyx57W2v1u12 submitted by klappvisor
[link] [30 comments]
Categories: Incoming News

How would you match on the type of exception returned?

Haskell on Reddit - Sat, 01/09/2016 - 11:19am

I'm writing a web service and I might have a function like this:

listUsers :: Connection -> IO (Either SomeException [User]) listUsers conn = try $ query_ conn "SELECT * FROM users"

This doesn't have to be catching exceptions thrown in query_, I could easily be talking about my own custom error type that's returned if the list is empty.

Now in my route handler I can easily match on the Left/Right values, but what if I want to match on the type contained inside Left, and return a different HTTP status code depending on the type? This might not be pretty or idiomatic but it illustrates what I'm trying to accomplish:

get root $ do eUsers <- liftIO $ listUsers conn case eUsers of Right users -> json users Left (BlahException ex) -> do setStatus status409 text "I am now going to explode" Left (FooException ex) -> do setStatus status418 text "I am now going to explode" Left (SomeException ex) -> do setStatus status500 text "I am now going to explode"

What is the Haskell way of doing this in your web service?

submitted by satan-repents
[link] [3 comments]
Categories: Incoming News

async docs not on hackage for some reason?

haskell-cafe - Sat, 01/09/2016 - 8:16am
Hello, Does anyone have any thoughts why the async docs aren't available on hackage yet? - https://hackage.haskell.org/package/async-2.1.0 It says this version was uploaded a few days ago, but no docs are available. I did a `cabal get` locally and build the docs using stack; so it works fine.
Categories: Offsite Discussion

Detecting type errors with GHCi commands?

Haskell on Reddit - Sat, 01/09/2016 - 5:36am

I do a lot of exploratory coding in GHCi, and as such, I'm tinkering with a script to persist definitions across GHCi sessions and reloads like so:

*> :sr narp = putStrLn "Narp!" *> :do m <- return "Ok" *> narp Narp! *> m "Ok" *> :q ...>ghci *> :ls *> narp Narp! *> m "Ok"

... and I've run into a snag. If I use :sr to define a function which does not type check, I still persist it. Now, I do have a :dl command to delete the last definition persisted with :sr, but that is subject to human error. Is there any fairly simple trick I'm overlooking that would let me catch this automatically?

Alternatively, is there something that already does this so I don't have to?

submitted by WarDaft
[link] [4 comments]
Categories: Incoming News

Is there any tutorial about the reducers package ?

Haskell on Reddit - Sat, 01/09/2016 - 3:32am

The question is in the title. I know that with the reducers, I can transform

getSum $ mconcat (map Sum xs)

to something like getSum $ reduce?? xs

or

??? getSum xs

But it always take me half an hour to figure out which import to do and which function to call. This package seems great though.

In the example I gave, it doesn't look really usefull, but it is when you reducing tuples and could do thing like

(getSum a, getSum b, getMax c) = reduce??? [(1,2,3), (4,5,6)] submitted by maxigit
[link] [2 comments]
Categories: Incoming News

Why is Apply defined as `forall a b. f (a -> b) -> f a -> f b`?

Haskell on Reddit - Fri, 01/08/2016 - 9:42pm

Even after years of programming in Haskell, I always get hung up on this when implementing Applicative or Apply for some type.

I get that <*> has this signature to allow the SomeConstructor <$> foo <*> bar pattern which is definitely useful. But why are applicative functor instances defined in this specific pattern, when, for example, forall a b. f a -> f b -> f (a, b) is isomorphic and may be easier to grok (given that there are similar patterns in other languages, for example Promise.all in JavaScript)?

Is it this way because of historic reason, is there a benefit to the former representation (performance?), or is it purely arbitrary?

submitted by srijs
[link] [21 comments]
Categories: Incoming News