News aggregator

type families with non-type indices

haskell-cafe - Wed, 10/08/2014 - 1:28pm
Is there an analog or variant of type families that is indexed by values rather than by types? An example of such a family is integers mod p. One wants to define the operations once for all p, so that a type for any particular p can be introduced by a one-line declaration. Of course this can be done with p being a run-time parameter: data Modp = Modp Integer Int instance Num (Modp) where (Modp x p) + (Modp y q) = if p==q then Modp ((x+y) 'mod' p) p else error "unequal moduli in Modp operation" But it would be better to catch the error at compile time and not have to check at every operation. Doug
Categories: Offsite Discussion

How to represent a list of opaque fingerprint data?

Haskell on Reddit - Wed, 10/08/2014 - 10:26am


I'm currently porting my efforts on finding function addresses in patched binaries in D to Haskell (FWIW, D:, Haskell: I do so by computing fingerprints consisting of certain characteristics for each function, its basic blocks that is.

In order not to have to save the base binary itself, I decided that every characteristic can return some opaque data in its characterize function which can later be accessed when computing the score in matchingScore.

There might be a characterizer counting instructions, where the payload might be an [Int] and another might compute a hash for early detection of unchanged functions. Both payloads are opaque to calling code. Nevertheless they should be handled in a uniform way, e.g. mappable. I figured I could use existential types for that, but it feels just wrong. Obviously, don't take the last two functions too seriously, it's just how I want to call it.

Here is what I got so far:

{-# LANGUAGE ExistentialQuantification #-} type Address = Int data Disassembly = MkDisassembly data Characterizer ch = MkCharacterizer { characterize :: Disassembly -> Address -> ch , matchingScore :: Disassembly -> Address -> ch -> Float } data GenericCharacterizer = forall ch . WrapCharacterizer (Characterizer ch) type Characterizers = [GenericCharacterizer] --computeCharacteristics :: Characterizers -> Disassembly -> Address -> [forall ch . ch] --totalScore :: Characterizers -> Disassembly -> Address -> [forall ch . ch] -> Float

I'm actually looking for design advice: As I see it, there are at least 3 different ways to achieve what I want:

  • Existentials as done here, although the last 2 functions can't function like that yet
  • Data.Dynamic
  • Data.HList.HList (only type safe solution, but also least extensible I think)

I hope I could convey what I mean. How would you design this if you knew that ch will never need to be accessed outside Characterizer functions (except for a possible serialization step later on)?

submitted by sgraf812
[link] [8 comments]
Categories: Incoming News

As a follow-up for my previous question, is this an acceptable way to encode "interferes" in Haskell?

Haskell on Reddit - Wed, 10/08/2014 - 9:36am
import Data.Array {- Hello, I'm trying to figure out how I am supposed to do "inheritance", or interfaces, in Haskell. Many solutions were suggested, but I personally tend to avoid typeclasses, so I've enjoyed this take: -} {- define a common Map interface as a type. -} data Map = Map { get :: Int -> Int, set :: Int -> Int -> Map } {- To implement a particular instance, we use another type... -} data ListMap = ListMap [Int] deriving Show {- And just a function to inject from that type into Map. -} makeMap (ListMap list) = Map { get = (list !!), set = \i x -> makeMap (ListMap (take i list ++ x : drop (i+1) list))} {- So a particular map can be created from a ListMap using makeMap. -} mp = makeMap (ListMap [0,1,4,9,16,25]) {- And it works... -} main = print $ (get mp 2, get (set mp 3 99) 3) {- Questions: 1. Is this linguistic? 2. Will I be yelled at if I do this instead of typeclasses from now on? 3. Is there any problem with this approach, in general, including performance? -} submitted by SrPeixinho
[link] [24 comments]
Categories: Incoming News

Proposal: Make a very slight change to the semantics of Data.List.isSuffixOf

libraries list - Wed, 10/08/2014 - 9:15am
Currently, isSuffixOf is defined like this: xs `isSuffixOf` ys = reverse xs `isPrefixOf` reverse ys If ys is much longer than xs, this is not so wonderful, because we have to reverse the whole spine of ys. It also will fail whenever either xs *or* ys is infinite. The following implementation seems a lot saner (although longer): isSuffixOf :: forall a . (Eq a) => [a] -> [a] -> Bool [] `isSuffixOf` _ = True needle `isSuffixOf` hay = maybe False (\fp -> needle `eq` getEndChunk hay fp) (getFrontPointer needle hay) where eq :: [a] -> [a] -> [a] (x:xs) `eq` (y:ys) = x==y && (xs `eq` ys) getEndChunk :: [a] -> [a] -> [a] getEndChunk (_:hy) (_:fp) = getEndChunk hy fp getEndChunk hy _ = hy getFrontPointer :: [a] -> [a] -> Maybe [a] getFrontPointer [] hy = Just hy getFrontPointer _ [] = Nothing getFrontPointer (_:nd) (_:hy) = getFrontPointer nd hy This doesn't do any of that crazy stuff, and it will w
Categories: Offsite Discussion

Range Performance.

Haskell on Reddit - Wed, 10/08/2014 - 8:41am

What is the difference between haskell's [x..x] and python's range()?

submitted by sprkyco
[link] [20 comments]
Categories: Incoming News

cabal sandbox: Can't load .so/.DLL for...

haskell-cafe - Wed, 10/08/2014 - 8:18am
Hi all, I have some trouble with cabal sandboxes. I used `cabal sandbox add-source` to add a library. When I add the library as a dependency for my project and try to build I’m always getting <command line>: can't load .so/.DLL for: /Users/joel/workspace/haskell/bookingsystem/.cabal-sandbox/lib/x86_64-osx-ghc-7.8.3/google-maps- (dlopen(/Users/joel/workspace/haskell/bookingsystem/.cabal-sandbox/lib/x86_64-osx-ghc-7.8.3/google-maps-, 9): Symbol not found: _googlezmmapszm0zi1zi0zi0_WebziGoogleziMapsziInternal_queryAPI_closure Referenced from: /Users/joel/workspace/haskell/bookingsystem/.cabal-sandbox/lib/x86_64-osx-ghc-7.8.3/google-maps- Expected in: flat namespace in /Users/joel/workspace/haskell/bookingsystem/.cabal-sandbox/lib/x86_64-osx-ghc-7.8.3/google-maps- I couldn’t find a solution so far. Anyone can help
Categories: Offsite Discussion

Functional Jobs: Software Engineer / Developer at Clutch Analytics/ Windhaven Insurance (Full-time)

Planet Haskell - Wed, 10/08/2014 - 7:26am

Position Description:

Windhaven Insurance is seeking an experienced Software Engineer/ Developer to join a small elite team who are disrupting the auto insurance industry with innovative technology. You will work in a startup atmosphere as part of a subsidiary of a rapidly growing larger company. This means that along with programming, you’ll have a hand in the larger issues, such as product architecture and direction.


  • Someone who knows at least one functional language such as: Elixir, Erlang, Lisp, Scheme, Haskell, ML, Clojure, Racket, Ocaml or F#
  • Someone who ENGAGES a.k.a “gives a damn” about what we do and how technology can help make us more competitive in the marketplace.
  • Someone who COLLABORATES. We have the flattest organization in the industry designed with one main goal – the TEAM. Are you hungry to make a significant impact in the tech world?
  • Someone who RESPECTS Teammates, customers and the community.

Special Requirements:

You need to have made an achievement, in any field, of significance worth talking about, that required grit, determination and skill. This can be a personal achievement that few know about, or it could have gotten coverage by the media. It doesn’t matter, what does matter is some demonstration of grit, determination and skill. If it can be described succinctly, please describe the achievement in your cover letter, if not, be prepared to tell us all about it during the interview.

Professional & Technical Qualifications:

  • Experience with languages such as Elixir or Erlang
  • Experience with Ember.js (or Angular.js)
  • Experience with NoSQL data stores, such as Couchbase, Riak, etc.
  • DevOps experience a plus
  • Ability to explain technical issues and recommend solutions
  • Strong team player with a high degree of flexibility
  • Excellent verbal and written communication skills


Competitive salary based on experience. Benefits package includes: medical, dental, vision insurance, life insurance, short term and long term disability insurance, 401K, paid time off. EOE.

Get information on how to apply for this position.

Categories: Offsite Blogs

IO Exceptions through monad transformers stack

haskell-cafe - Tue, 10/07/2014 - 10:25pm
Hi, I’m not sure if this is the right list for “base” questions like this, if there are any more specific lists please let me know. I’m writing a parser and it works in a stack of monad transformers defined in this way: type Parser = StateT ParserState (ExceptT ParserError IO) The base monad is IO because the parse could have the need to load other files included by the file that’s being parsed. The ExceptT transformer make it easy for the lexer and the parser to signal errors. At the end I have a runParser function that compose runExceptT and evalStateT and provides me with a nice Either that contains the parsed result or a value of type ParserError. The ParserError data type is the following: data ParserError = LexingError <fields> | ParsingError <fields> Currently, whenever the parser encounter an error I simply do throwError $ ParsingError something…, for example. What I would like to do is to report in this way also the possible IO errors that can occur, by adding a IOError construc
Categories: Offsite Discussion

Fingerprinting Haskell Objects

haskell-cafe - Tue, 10/07/2014 - 9:30pm
Hello everybody, I have a little question I wanted to run by the folks here. I've run into it several times over the past few years and would love to lock down a good answer. What's the best way to "fingerprint" a Haskell object into, say, ByteString, so that this fingerprint can be used as the "lookup key" in a database (for example) and be trusted that it will remain constant over time even as the underlying libraries evolve? Here's a simple example: - Say I'm building a manual index on top of a key-value store (redis, dynamodb, etc.) - I want my keys to be arbitrary tuples (or similar records) that may contain various fields in them - I would like to avoid ad-hoc, hand-written MyTuple -> ByteString and ByteString -> MyTuple conversions. However, Generic derivations, template-haskell, etc. are acceptable - Notice how your fingerprint, which is used as a lookup key in the database, has to remain stationary. If it changes even by a single bit over time for the same MyTupl
Categories: Offsite Discussion

[help] Setting up Haskell on a Mac?

Haskell on Reddit - Tue, 10/07/2014 - 8:36pm

I've got GHCI running fine, but I'm having a hard time setting my editor. Does anyone know how? I'm super new to OSX which doesn't help.

It was easy on windows using :set editor <path>

But that isn't the case here it seems.

Also, anything else I'll need to get up and running on OSX would be awesome.

Thanks in advance.

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

ANN: islink check if an HTML element is a link (useful for web scraping)

haskell-cafe - Tue, 10/07/2014 - 7:59pm
Hello everybody, I'd like to announce the first public release of islink. It's library that basically provides a list of combinations of HTML tag names and attributes that correspond to links to external resources. This includes things like ("a", "href"), ("img", "src"), ("script", "src") etc. It also comes with a convenience function to check if a particular pair (tag, attribute) corresponds to a link. This can be useful for web scraping. Here's an example how to use it to extract all (external) links from an HTML document (with the help of hxt): {-# LANGUAGE Arrows #-} import Text.Html.IsLink import Text.XML.HXT.Core
Categories: Offsite Discussion