GHC 7.8.1 released
haskell.org
haskell.org
One thing I'm particularly excited about is the switch to use the system's dynamic linker instead of a custom one in GHCi. The custom linker GHCi used before didn't support some features used by C++ code, which meant that some of my FFI-based projects weren't usable in GHCi. This also affected other things that used a GHCi-like code path like Template Haskell and the GHC APIs used by ghc-mod/hdevtools. This will be huge for usability for me when working on projects that link to C++.
Hat tip to all the GHC developers for a truly amazing release!
Truthfully, me and Simon now have reservations about if this is the right way to go, and we should instead invest more infrastructure into our own Linker (which, independently, got some nice bug fixes this time around - constructors and weak pointers now work, for example.) ELF support is quite complete (and very stable) for example. It's just a question of what's the most work.
This extension allows programmers to use the list notation for construction of structures like: Set, Map, IntMap, Vector, Text and Array. The following code listing gives a few examples:
['0' .. '9'] :: Set Char
[1 .. 10] :: Vector Int
[("default",0), (k1,v1)] :: Map String Int
['a' .. 'z'] :: Text
http://www.haskell.org/ghc/docs/7.8.1/html/users_guide/type-...
Yes. Data.ByteString.Char8.pack does not form an isomorphism with Data.ByteString.Char8.unpack. It is thus not interchangeable with String.
Example:
Prelude Data.ByteString.Char8> putStrLn . unpack . pack $ "Российская Федерация"
>AA89A:0O $545@0F8O
And here the correct result with Data.Text: Prelude Data.Text> putStrLn . unpack . pack $ "Российская Федерация"
Российская Федерация "foo" :: String
and with we have "foo" :: IsString a => a
much like 3 :: Num a => a
It inherits all of the same weaknesses and strengths that we have with the Num typeclass. instance IsString () where
fromString = const ()
And there's nothing wrong with it! pack "<unicode> string"
fromList [1,2,3,4,4.000000000000000000000000001]I think that sort of ambiguity is part of Haskell. It rescinds a bit on the HM promise of never having to write types, but Haskell has long rescinded on that in spirit and practice. It leads to a bit of beginner trouble, but, again, not any more than numeric literals do.
I welcome overloaded lists because I feel it'll make more libraries willing to expose Set-typed interfaces when that's the honest contract that should be upheld by the interface. That's what I want my types to tell me—not just what's syntactically convenient.
{-# LANGUAGE ViewPatterns, PatternSynonyms #-}
import Data.Set as S
-- patterns that a library might provide
pattern x :< m <- (minView -> Just (x, m))
pattern m :> x <- (maxView -> Just (x, m))
pattern Null <- (S.null -> True)
-- a really dumb test function using those patterns
doubleMin :: (Ord a, Num a) => Set a -> Set a
doubleMin (x :< s) = insert (2 * x) s
doubleMin x = x
Ignore how dumb my test function is, and just focus on how lightweight it becomes to match views of the data structure. Figuring out what patterns to include my libraries is going to be a fun new design point. pattern (x :< m <- minView) -> Just (x,m)
but that's just basically view patterns/pattern guards. Basically I can sort of see what's going on here, but only in this specific case; I can't see how one uses this elsewhere.The PatternSynonyms extension enables two new top-level declarations, both declared with "pattern".
pattern NestedJust x = Just (Just x)
pattern NestedNothing = Just Nothing
That's the easier syntax of a bidirectional pattern synonym. They can be used both as patterns and as expressions. foo :: Maybe (Maybe Int) -> Bool
foo (NestedJust 7) = True
foo (NestedNothing) = False
foo _ = False
bar :: Maybe (Maybe String)
bar = NestedJust "hello"
There are a couple terrible examples. Bidirectional pattern synonyms must be valid as both expressions and pattern matches, or you get a compile errorMy example was using unidirectional pattern synonyms. They allow any pattern match whatsoever as the body; the expression restriction is dropped because they aren't allowed to be used in expression contexts. They are defined using <- instead of =.
pattern MinView x m <- (minView -> Just (x, m))
That's functionally the same as the :< example above, but possibly a bit simpler to read, because the precedence of the symbols is more obvious. It defines a pattern synonym named MinView that is translated to the view pattern in parens.It's quite possible you were conflating view pattern syntax with pattern guard syntax as the source of your confusion.
> With Mio, realistic HTTP servers in Haskell scale to 20 CPU cores, achieving peak performance up to factor of 6.5x compared to the same servers using previous versions of GHC. The latency of Haskell servers is also improved: <snip> under a moderate load, reduces expected response time by 5.7x when compared with previous versions of GHC
> Available with GHC 7.8.1
Nice job.
Thanks for all the responses. I'll start with LYAH.
There is also Real World Haskell [0]. It's a lot less long winded than LYaH, which is good or bad depending on how you like to digest information.
Also, check out FP Complete's FP Haskell Center [1]. It contains community written tutorials with inline runnable code examples, so you can really get a feel for Haskell by manipulating and playing with the examples right on the site.
Sounds kind of miserable, right?
That's why you should also prepare for it with some of that early curiosity and wonder that drove us all to learn programming to begin with.
Haskell is probably unlike anything you've used before.
http://www.haskell.org/haskellwiki/H-99:_Ninety-Nine_Haskell...
Here is the list of materials I used to learn Haskell:
1. LYAH, http://learnyouahaskell.com/
2. Real world Haskell: http://book.realworldhaskell.org/read/
3. Programming in Haskell: http://www.amazon.com/Programming-Haskell-Graham-Hutton/dp/0... (No one suggests this book, but I do think this book is well-written and concise.)
4. Video tutorial by Erik Meijer based on Programming in Haskell: http://channel9.msdn.com/Series/C9-Lectures-Erik-Meijer-Func...
5. Advanced topics: http://www.haskellforall.com/2014/03/introductions-to-advanc...
Edit: Format
To learn something that hard, you need to be exposed to it multiple times. You'll probably get overwhelmed even with LYAH, but give it some time and come back to it.
All questions have solutions you can learn from; most have multiple solutions. I have learned a lot from doing these problems and doing additional research where needed.
(This is in addition to the other good learning resources like the oft mentioned LYAH.)
I suggest HFH ("Haskell Fast & Hard") as the introductory tutorial to start with instead. You can pick from 2 formats:
- http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way... - static all-in-one-page format with pretty pictures
- https://www.fpcomplete.com/school/to-infinity-and-beyond/pic... - split version, but with the ability to open snippets in their web based IDE
...after this, Real World Haskell is probably the next step: http://book.realworldhaskell.org/read/ (I'm still at this step).
Running through some chapters of Real World Haskell online, however, is proving to be a bit of an eye opener ;-)
Might just be that I could care less about hand drawn illustrations and the occassional somewhat humerous aside.
YMMV, many seem to love LYAH.
This forces you to put all your code into method signatures. This, in turn, means Haskell (or C, if you follow the 1 semicolon rule in C) can understand almost everything about your program.
If you actually follow the 1 semicolon rule in C, you'll get very verbose syntax. All of Haskell's syntax is in service of making programming in this style palatable.
1. Has taught a lot of Haskell
2. Thinks LYAH is better as a reference than a step-by-step method for learning Haskell
Then see my Learning Haskell gist here (it includes Haskell Fast & Hard, and other things too).
https://gist.github.com/bitemyapp/8739525
If anybody is learning Haskell and needs help, please email me.
Edit: I agree with nnq, I think LYAH moves too slowly and fails to show you what about Haskell is truly different and worthwhile in a compact enough format. That said, it is great as a reference as the explanations of concepts are stand-alone. (unlike RWH which is more project-oriented)
Edit2: You are going to feel a bit lost after Haskell Fast & Hard. This is natural. That's why I have you do the NICTA course. It firms things up.
Edit3: I think RWH is a great reference as well, but the mid-to-late chapters have a bit of an "in media res" thing going on because there are projects being walked through cross-chapter. That said, it has a very nice and simple example of, "pre-monads, ugly code; post-monads, pretty code". RWH also covers topics that you'll care about if you're doing Haskell in production.
I do it every year but hit io monads and my mind continually just has a core dump. Some year I hope to climb everest.
Stop doing that. I explicitly say in my gist:
"Most of all, don't sweat the stuff you don't understand immediately. Just keep moving."
IO is not important. It behaves no differently at a basic level than any other monad. Monads themselves are just an interface.
Don't put the knowledge on a pedestal, just keep hacking Haskell. It'll all come with time.
This blog post of mine might lend some intuition for monads (including IO): http://bitemyapp.com/posts/2014-03-24-monads-bind-join-actio...
But don't get stuck. It doesn't matter. Just write Haskell code. The compiler won't let you do anything too crazy anyway.
Also, there's no substitute for talking to people. Hop on the Haskell Beginners mailing list (http://www.haskell.org/mailman/listinfo/beginners) or drop by the IRC channel (#haskell on freenode), where people couldn't be friendlier.
Then again, that might be because when I looked into Haskell, I realised it was the language I wished to create.
You might like this:
http://www.haskell.org/haskellwiki/Haskell_Tutorial_for_C_Pr...
And the Gentle Introduction is not very gentle but is a good reference:
(I'm a Haskell beginner, currently experimenting with using Scotty, Persistent and Esqueleto to make a web API - and these articles have been so useful to me - I'm finally getting my head around monad transformers, using them to extend the standard Scotty one. Proud moment for me.)
Both are helping my limited experience of Haskell greatly.
[0]: https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompilin...
How crazy would it be if the Twitter app was over 50M, or Facebook Messenger over 80M?
I'd also highly recommend c2hs for writing new wrapper libraries.
This is actually what the Objective-C compiler does. It translates your Objective-C code to C method calls.
It's not ridiculously hard, but it's somewhat less easy than normal C FFI.
http://stackoverflow.com/a/2573949
http://stackoverflow.com/a/18689338
If you're interested in the nitty-gritty of how objc_msgSend works, bbum from Apple wrote up a great low-level walkthrough a few years back: http://www.friday.com/bbum/2009/12/18/objc_msgsend-part-1-th...
If you really need to construct calls at runtime and you don't know the argument list at compile time, there's a Haskell binding to libffi. However, you generally only need that if you're writing a language interpreter or similar.
Details here: http://research.microsoft.com/en-us/um/people/simonpj/papers...
You should only use prefetch when benchmarks show that the hardware prefetch isn't performing up to sniff. Or when your access pattern for data doesn't have good locality and doesn't resemble a linear arithmetic sequence. (Just rules of thumbs mind you. For more precise heuristics, please read your CPU vendors optimization manual. The intel manual has quite a few tricks that should apply to most modern CPUs overall)
The unpacked binary distribution is closer to 1GB, which sounds about right. I speculate Arch Linux is doing a regular build with nothing special.
If 1GB is undoable for your laptop (which I find odd, as someone even on a 100GB device), then that's unfortunate. You're best to wait for some other build with things removed or to just build it yourself (for example, no dynamic linking).
There's no benefit to handcuffing yourself to the platform. Just install ghc and cabal, and enjoy yourself.
Should I download a package from http://deb.haskell.org/? If so, where can I find 7.8.1?
They are packaged for Ubuntu, technically (12.04 Precise) but you can just add the apt-repository line to your `sources.list` and it will work fine, and plenty of people are doing this.
A repository for the STABLE branch will eventually appear on http://deb.haskell.org, but I'm not sure when Joachim will do this.
As easy as:
tar -xJvf ghc-7.8.1-i386-unknown-linux-deb7.tar.xz
cd ghc-7.8.1
./configure --prefix=/opt/ghc-7.8.1
make installJust kidding, Haskell is a great language, it's unfortunate that the tooling is still way behind (at least on Windows) and that it isn't used much.