Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Hughmoris
Apr 21, 2007
Let's go to the abyss!
Poking around Haskell and Functional programming by reading the "Learn You A Haskell" book. In one of the earlier sections, its talking about syntax in functions. It has this example:

code:
lucky :: (Integral a) => a -> String  
lucky 7 = "LUCKY NUMBER SEVEN!"  
lucky x = "Sorry, you're out of luck, pal!" 
If I was describing this function to someone, how would I verbalize that first line? I understand what the function does but I'm not positive what " lucky :: (Integral a) => a -> String" is telling me.

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!

dirby posted:

informally: "lucky is a function from Integral things to Strings."
I think this is better: "For each integral type a, there is a corresponding object called lucky which has the type of a function from things of type a to things of type String"

Someone who knows a lot about Haskell/theory can probably phrase it better/correct me.

Arcsech posted:

I would say that as something like "From any Integral type to String." The first part in parentheses indicates that a must implement the type class Integral, then the rest reads like a normal type signature, with that restriction.

KaneTW posted:

"lucky is a function from any Integral type to String" sounds good to me. Maybe "from any type that's an instance of Integral to String" but while a bit more accurate it's also a mouthful

Got it, thanks.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I dabble with programming as a hobby, mainly in Perl and Python. Trying my hand at functional programming with Haskell. I've read in multiple places that functional programming makes concurrency/parallel programming much easier, and that functional programming scales really well.

Could someone explain at a simpleton level why these things are easier with functional programming compared to OO/imperative languages?

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Thanks for the explanations/thoughts on functional programming and parallelism/concurrency. Still working my way through beginner tutorials in Haskell, think I'm going to drop the $60 on the Haskell Programming From First Principles book.

Hughmoris fucked around with this message at 00:09 on Apr 2, 2016

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Still working my way through the the haskell book and am having a hard time understanding this example. Its an if/else example function:

code:
greetIfCool :: String -> IO ()
greetIfCool coolness =
if cool
  ...
else
  ...
where cool = coolness == "downright frosty yo"
I'm getting tripped up on the where statement. What is that statement telling me?

*I tried to include the full code snipped but SA is flagging me with a cloudflare error... It doesn't like something in the code sample.

Hughmoris fucked around with this message at 02:09 on Apr 11, 2016

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Asymmetrikon posted:

"Where" means that they're defining a term used in the definition of the function. It may be a little easier to understand with 'let' syntax and some parens:

code:
greetIfCool :: String -> IO ()
greetIfCool coolness =
  let
    cool = (coolness == "downright frosty yo")
  in
    if cool
    then ...
    else ...
So we're saying that "cool"'s value is true if the argument coolness is equal to "downright frosty yo", then using "cool" as a Boolean value in the if statement.

That makes sense, thanks.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I realize this is pretty vague but for those who use Haskell, what type of projects have you used it for? I'm making another try at wrapping my head around functional programming with Haskell and looking for inspiration on some projects that people have use the language for. Outside of large, enterprise-size applications.

Adbot
ADBOT LOVES YOU

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Any recommended F# blogs and tutorial videos? I tried to wrap my head around FP using Haskell and it just wasn't taking, so I figure I'll give F# a whirl.

  • Locked thread