I really want to get into Haskell, but I just don't understand it. The tutorial on the official site doesn't do it for me. Can anyone suggest alternative resources for learning? I'm used to C-like languages. Thanks for all the responses. I'll start with LYAH.
GHC 7.8.1 released
81–90 of 103 posts
Re: GHC 7.8.1 released
#82I really want to get into Haskell, but I just don't understand it. The tutorial on the official site doesn't do it for me. Can anyone suggest alternative resources for learning? I'm used to C-like languages. Thanks for all the responses. I'll start with LYAH.
Then again, that might be because when I looked into Haskell, I realised it was the language I wished to create.
Re: GHC 7.8.1 released
#83Earlier quoted context omitted.
The other hard part about it is that Haskell's FFI doesn't support variadic functions in a friendly way, which makes argument passing that much trickier.
There is a similar problem with objc_msgSend in C: Methods with certain argument types can't be called with a normal objc_msgSend(). Instead, you need to create a specifically typed function pointer and assign objc_msgSend to it. I think a similar solution would be necessary with Haskell.
Re: GHC 7.8.1 released
#84Earlier quoted context omitted.
It's not that easy. I mean, just sending a message could entail one of objc_msgSend, obj_msgSend_stret or objc_msgSend_fpret, and which one you want to use is not always as clear-cut as you might prefer ( http://www.sealiesoftware.com/blog/archive/2008/10/30/objc_e... ). And then there's the hassle of defining classes dynamically, which entails six function calls just to create a class with one empty method, and one…
The other hard part about it is that Haskell's FFI doesn't support variadic functions in a friendly way, which makes argument passing that much trickier.
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.
Re: GHC 7.8.1 released
#85Earlier quoted context omitted.
I'm also intrigued. How would one program for iOS in a practical sense with Haskell? A great deal of iOS programming, as I understand it, is navigating the APIs and libraries provided by the SDK... is this a simple task in Haskell? The FFI is something I haven't really dealt with much yet. I guess people could/will start writing wrapper libraries?
Haskell has one of the best FFIs I've ever seen; calling C code from Haskell is quite trivial, and you can write all of the necessary wrapper code and objects (such as automatic memory management or object destruction) in Haskell using common wrappers. I'd also highly recommend c2hs for writing new wrapper libraries.
Re: GHC 7.8.1 released
#86Earlier quoted context omitted.
There is a similar problem with objc_msgSend in C: Methods with certain argument types can't be called with a normal objc_msgSend(). Instead, you need to create a specifically typed function pointer and assign objc_msgSend to it. I think a similar solution would be necessary with Haskell.
I'd appreciate seeing a link to an example of this. I put a decent amount of work (a few years ago) into writing some bindings in Haskell to the objc runtime, but ended up shelving it until I could come up with a satisfactory solution to the variadic function dilemma.
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...
Re: GHC 7.8.1 released
#87Earlier quoted context omitted.
Haskell has one of the best FFIs I've ever seen; calling C code from Haskell is quite trivial, and you can write all of the necessary wrapper code and objects (such as automatic memory management or object destruction) in Haskell using common wrappers. I'd also highly recommend c2hs for writing new wrapper libraries.
Doesn't calling C code interact poorly with green threading? (I assume that handlers that make it act slightly sanely exist, but I imagine the cost of setting up native threads for FFI is rather high.)
Re: GHC 7.8.1 released
#88I've been playing around with the new PatternSynonyms extension. In combination with the existing ViewPatterns extension, I'm going to really have to change the way I think about API design. This is actually pretty fantastic. {-# LANGUAGE ViewPatterns, PatternSynonyms #-} import Data.Set as S -- patterns that a library might provide pattern x : Just (x, m)) pattern m :> x Just (x, m)) pattern Null True) -- a really d…
pattern (x : 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.Re: GHC 7.8.1 released
#89I've been playing around with the new PatternSynonyms extension. In combination with the existing ViewPatterns extension, I'm going to really have to change the way I think about API design. This is actually pretty fantastic. {-# LANGUAGE ViewPatterns, PatternSynonyms #-} import Data.Set as S -- patterns that a library might provide pattern x : Just (x, m)) pattern m :> x Just (x, m)) pattern Null True) -- a really d…
I haven't had a look at the extension definition itself, but I find this really hard to read. Can you or someone else give an explanation of what's going on? It seems to me that the brackets are all wrong, I would've expected pattern (x : 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 el…
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
pattern MinView x m Just (x, m))
That's functionally the same as the :It's quite possible you were conflating view pattern syntax with pattern guard syntax as the source of your confusion.Re: GHC 7.8.1 released
#90Earlier quoted context omitted.
I sincerely recommend against LYAH! It takes sooooooooo loooooong to get to the interesting bits that actually make Haskell worth learning an has so many try-to-be-funny examples that it makes you run away screaming... I tried going through it but it was literally oscillating between putting my mind to sleep and making wish to grab a chainsaw :) And the "humor" and "pretty pictures" don't help either... they were mor…
I accidentally upvoted you, but I disagree. LYAH is a great book to actually read through, and I enjoyed the humor. real world haskell introduces things without explaining and it's quite confusing and inconsistent.