# News aggregator

### Read and sort text file?

Hi, I've recently decided to pursue Haskell as the language of choice for a school project and, being the beginner I am, have found myself hitting a wall.

The assignment is to take in a list of names, sort it, then print it out. Reading in the list of names was easy, as was printing it out. The wall I'm hitting is sorting it. From what I'm seeing, and correct me if I'm wrong, when it read in the file it just popped all the characters into a string. When I tried to use the sort function, it sorted each character, including the new line characters.

I've searched high and low and the solutions I found that most represent my problem involve integers instead of strings and don't fully explain what's happening.

Like I said before, I don't know a lot about Haskell and there isn't anyone I know that I can physically ask for help. From my understanding, one thing I could potentially do is group each line and then sort the list, which should actually sort the words rather than the characters, but I'm having a hard time figuring out the syntax for that. I'm going to continue to research this, but hopefully someone here can help and give me more specific advice.

Thanks.

submitted by pakispride[link] [10 comments]

### Why is vs `Data.Monoid.mappend` [v] better than vs ++ [v]

HLint recently made the following suggestion to me:

Use mappend Found: vs ++ [v] Why not: vs `Data.Monoid.mappend` [v]I was trying to append a single element to an existing list. What are the benefits of using mappend instead of (++) ? Other than that you get the generality? Because it sure isn't more pleasing to the eye or easy on the fingers.

submitted by stasiana[link] [21 comments]

### CFP: FHPC 2015: Workshop on FunctionalHigh-Performance Computing [w/ICFP]

### CFP: FHPC 2015: Workshop on Functional High-PerformanceComputing [w/ICFP]

### Definition of fix

fix is defined in Data.Function as

fix f = let x = f x in x

As far as I can tell, this is equivalent to

fix f = f (fix f)

which seems much clearer. Does anyone know why the first version was chosen?

submitted by anschelsc[link] [15 comments]

### Implementing zip for a dependently typed list using GHC.TypeLits?

The following implementation of a dependently typed list compiles without problems:

{-# LANGUAGE DataKinds, GADTs, KindSignatures #-} module DTListPeano where data Nat = Z | S Nat data DTList :: Nat -> * -> * where Nil :: DTList Z a Cons :: a -> DTList n a -> DTList (S n) a zip' :: DTList n a -> DTList n b -> DTList n (a,b) zip' Nil Nil = Nil zip' (Cons x xs) (Cons y ys) = Cons (x,y) $ zip' xs ysHowever, I wanted to use GHC.TypeLits, so I tried the following, which won't compile though:

{-# LANGUAGE DataKinds, GADTs, KindSignatures, TypeOperators #-} module DTListTypeLits where import GHC.TypeLits data DTList :: Nat -> * -> * where Nil :: DTList 0 a Cons :: a -> DTList n a -> DTList (n+1) a zip' :: DTList n a -> DTList n b -> DTList n (a,b) zip' Nil Nil = Nil zip' (Cons x xs) (Cons y ys) = Cons (x,y) $ zip' xs ysThe error message I get is:

DTListTypeLits.hs:13:53: Could not deduce (n2 ~ n1) from the context (n ~ (n1 + 1)) bound by a pattern with constructor Cons :: forall a (n :: Nat). a -> DTList n a -> DTList (n + 1) a, in an equation for ‘zip'’ at DTListTypeLits.hs:13:7-15 or from (n ~ (n2 + 1)) bound by a pattern with constructor Cons :: forall a (n :: Nat). a -> DTList n a -> DTList (n + 1) a, in an equation for ‘zip'’ at DTListTypeLits.hs:13:19-27 ‘n2’ is a rigid type variable bound by a pattern with constructor Cons :: forall a (n :: Nat). a -> DTList n a -> DTList (n + 1) a, in an equation for ‘zip'’ at DTListTypeLits.hs:13:19 ‘n1’ is a rigid type variable bound by a pattern with constructor Cons :: forall a (n :: Nat). a -> DTList n a -> DTList (n + 1) a, in an equation for ‘zip'’ at DTListTypeLits.hs:13:7 Expected type: DTList n1 b Actual type: DTList n2 b Relevant bindings include ys :: DTList n2 b (bound at DTListTypeLits.hs:13:26) xs :: DTList n1 a (bound at DTListTypeLits.hs:13:14) In the second argument of ‘zip'’, namely ‘ys’ In the second argument of ‘($)’, namely ‘zip' xs ys’Am I missing something obvious here?

submitted by Regimardyl[link] [3 comments]

### Practical equality constraint solver in the wild!

While trying to answer this SO question, I stumbled upon a Nat equality constraint solver plugin I had never seen before, made by Christiaan Baaij.

I haven't seen any announcements for it, so I thought the community might find it interesting.

It allows us to do exactly what the author of the SO question had in mind, namely solve the equality ((n1 + n2) - 1) ~ ((n1 - 1) + n2) which I find extremely powerful compared to what I've seen earlier.

With apologies to the author of the question, here is the working example:

{-# LANGUAGE RankNTypes #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE KindSignatures #-} {-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-} import GHC.TypeLits data List (n :: Nat) a where Nil :: List 0 a (:>) :: a -> List n a -> List (n + 1) a infixr :> append :: forall n1 n2 a. ((n1 + n2) - 1) ~ ((n1 - 1) + n2) -- Explicit constraint unnecessary! => List n1 a -> List n2 a -> List (n1 + n2) a append Nil ys = ys append (x :> xs) ys = x :> append xs ys foo :: List 2 Integer foo = 1 :> 2 :> NilAnd according to the Haddocks, much more impressive things are possible and practical!

submitted by srhb[link] [5 comments]

### ANN: dns-server: forward DNS queries to StatDNS RESTAPI

### Providing a beginner platform to Haskell

Hello fellow Haskellers,

I'm a CompSci student from Belgium and picked up Haskell about half a year ago in a course on declarative programming languages. Since then, I got really interested in the language and started attending the User Group meetings at my university. Struggling with the concepts there, I decided to restart my learning from zero.

I found the tutorial of bitemyapp on GitHub and I am working my way through it. I feel lucky I have read LYAH and had lectures of my own, but I feel that for someone without those extra's, picking up knowledge and experience from the reading material there can be quite a hard task.

Therefor I decided to put all my solutions to the homeworks online (on my GitHub) together with a ReadMe explaining the thought process behind the exercises.

My question now has 2 parts. First off, are there any legal problems with this? I'm re-using other people's material, although I credit them (for now it's just Brent Yorgey, but everything I learn, every exercise I make will be on there).

Secondly I'm open to criticism. What do you think of my coding and writing style? You can read a first mini-tutorial at CIS 194/Homework 1. (I have to finish that tutorial and rewrite a few parts of my code to match the tutorial. Also, should I document my code or would the ReadMe be enough?)

Thanks in advance

submitted by MusicalWatermelon[link] [14 comments]

### Extended Deadline (May 1), VSTTE'15

### New haddocks on Hackage now have links to instance sources!

I noticed this while browsing the haddocks for Earley -- check out those lovely "Source" links next to "instance Functor (Prod r e t)"... it's beautiful!

submitted by dmwit[link] [15 comments]

### [FUN] Cheryl's birthday; solved using Haskell/SBV

### Wrote a web app for generating Entity Diagrams from a textual description (in Haskell). Could you help me understand what I could do better next time?

### "Cogito, ergo sum"

I am not a number: I am a free variable. -- Conor McBride

I am not a free variable, I am a free monad! -- Edward Kmett

Wikipedia states:

Informally, a free object over a set A can be thought as being a "generic" algebraic structure over A: the only equations that hold between elements of the free object are those that follow from the defining axioms of the algebraic structure.

Let (C,F) be a concrete category (i.e. F: C → Set is a faithful functor), let X be a set (called basis), A ∈ C an object, and i: X → F(A) a map between sets (called canonical injection). We say that A is the free object on X (with respect to i) if and only if they satisfy this universal property:

for any object B and any map between sets f: X → F(B), there exists a unique morphism g: A → B such that f = F(g) o i.

In this way the free functor that builds the free object A from the set X becomes left adjoint to the forgetful functor.

There are several ideas running interleaved through my head at the moment (in no particular order):

- Vectors, lists, trees, complex numbers, "7 trees in one"
- Combinatorial species, calculi, "programming" languages
- Conor's answer about cursors and comonads [1] (and his thesis...)
- Monads joining, duplicating, returning, (aka "binding"), extracting (aka "cojoining"), Clowns and Jokers, Leibniz (and "Triples" :P)
- Adjoints, adjucnctions, holes, continuations, representations, Yoneda, Kan extensions, machines, and homotopy
- "All concepts are Kan extensions"
- Points, lines, circles, Euclid and Cartesian-ness
- Completeness, incompleteness, and causality
- Logic, type theory, syntax, semantics, Truth, and communication
- Peter Hancock's "AMEN" paper, logarithms, Church Numeral / Turing Machine duality, specifically "And so, lambda-calculus and Turing machine are duals: In a (universal) TM, an integer encodes an operation. In lambda-calculus, an operation encodes an integer." Numerals and lists in lambda-calculus: P-numerals
- Church vs. Curry typing and other paradigmatic "dualities"
- Lawvere's fixed point theorem, Yanofsky's exposition, and "heterological"
- Lenses, prisms, isos, traversals, and telescopes.
- What the Tortoise said to Achilles.
- Terminology is a minefield
- How, where, when, why, to what, to who any of these things matter (theoretically, pedagogically, and practically) and their "connections"?
- Whether this is all just a bunch of abstract nonsense and should forget about it?
- Much else
- Last, but certainly not least, bad puns :)

Just thinking out loud... Other than that, just thought I would stop by and say hello. I'll be updating with other references if anyone else is interested. Anyhow, back to the trenches.

[1]: Writing cojoin or cobind for n-dimensional grid type "Jagger/Richards: you can't always get what you want, but if you try sometime you just might find that you get what you need."

submitted by ShadowyOrdeal[link] [1 comment]

### Python anti-patterns are mostly all solved by Haskell

I ran across this in /r/python today:

http://www.reddit.com/r/Python/comments/33h964/the_little_book_of_python_antipatterns/

I thought it was a very good collection of anti-patterns. But I also realized that the vast majority of those anti-patterns, the bits of code you should **not** write, are impossible to write in Haskell, and this made me feel a bit smug.

This is not really news, because static typing solves so many problems that duck-typed languages create. But some of the items that stood out to me were:

- Never return more than one value from a function
- Never use the global statement
- Don't compare things to None using the == operator
- Do not use type() to compare types, use instance of Of course this is kind of an apples-to-oranges comparison, given that Python and Haskell's typing system are completely different.
- Use dict comprehensions to make dictionary initialization more readable Haskell has supported list comprehensions from the beginning.
- Always use zip() to iterate over lists

You can educate your developers to avoid these anti-patterns, or you could use just use a statically typed language and have the type checker enforce these rules for you.

It blows my mind that anyone would even consider using Python for large software projects, or anything apart from simple ad-hoc scripting to automate simple day-to-day tasks.

submitted by Ramin_HAL9001[link] [14 comments]