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
VikingofRock
Aug 24, 2008





Thanks, this is great. I added it to the OP. Also, drat, I really need to get into Elm more!

Adbot
ADBOT LOVES YOU

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
a monad is a monoid in the category of endofunctors

gonadic io
Feb 16, 2011

>>=
Is this thread a monad?

Pollyanna
Mar 5, 2005

Milk's on them.


I'll mo your nad.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Malcolm XML posted:

a monad is a monoid in the category of endofunctors

This is the best way I've ever seen this explained. You don't even need to know anything about anything, just read it as unknown symbols and you can see what that quote is getting at:

Jerry Bindle
May 16, 2003

fart simpson posted:

This is the best way I've ever seen this explained. You don't even need to know anything about anything, just read it as unknown symbols and you can see what that quote is getting at:



Thanks, this is unironically helpful. At first it looks like a bunch of gibberish, but I've convinced myself that I understand it after staring at it for a bit.

brap
Aug 23, 2004

Grimey Drawer
I really think whoever devised the wikipedia definition of monad should be shot.

Math articles on Wikipedia in general are impenetrable gibberish.

Su-Su-Sudoko
Oct 25, 2007

what stands in the way becomes the way

Yeah, they're rarely a good way to learn anything new.

Jerry Bindle
May 16, 2003
Math articles on wikipedia read like they were written by someone jacking off to how much smarter they are than everyone else. I guess it is supposed to be a reference, not a text book, but Its hard to find math text books that aren't too advanced or too basic.

I'm trying to relearn modern algebra, this book is excellent in terms of being fast paced without assuming too much about how much you already know. http://www.amazon.com/gp/product/0486474178

Eeyo
Aug 29, 2004

This was kind of covered earlier with the haskell course from UPenn, but are there other sources of "homework assignments" in functional languages? I can read a book until I'm blue in the face but it's useless without something to work on. Nothing too big either, I don't want to write some giant program that I could have done in any other language, I just want to have the important features highlighted in the assignment. This is one of the reasons I didn't really like learn you a haskell/erlang. It talked about a lot of stuff but that's pretty much fluff, I would have preferred a helpful reference and some assignments.

my homie dhall
Dec 9, 2010

honey, oh please, it's just a machine

Eeyo posted:

This was kind of covered earlier with the haskell course from UPenn, but are there other sources of "homework assignments" in functional languages? I can read a book until I'm blue in the face but it's useless without something to work on. Nothing too big either, I don't want to write some giant program that I could have done in any other language, I just want to have the important features highlighted in the assignment. This is one of the reasons I didn't really like learn you a haskell/erlang. It talked about a lot of stuff but that's pretty much fluff, I would have preferred a helpful reference and some assignments.

I really liked Write Yourself a Scheme in 48 Hours

VikingofRock
Aug 24, 2008




Real World Haskell has some exercises as well.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Just a note about Elm, I've found this set of tutorials, Elm By Example and I wished I'd started here.

I like the idea behind Elm so far, but it's in version 0.15 and it shows. A lot of rough around the edges stuff. I'm going to stick with it though.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

HappyHippo posted:

Just a note about Elm, I've found this set of tutorials, Elm By Example and I wished I'd started here.

I like the idea behind Elm so far, but it's in version 0.15 and it shows. A lot of rough around the edges stuff. I'm going to stick with it though.

Yeah, I wouldn't use Elm for anything that "matters" yet. It's still pretty young and rapidly changing, with a major, compatibility breaking release about once every 3 months. But the core concept doesn't change, and that's what I really like about it.

leftist heap
Feb 28, 2013

Fun Shoe
Does someone want to take a stab at explaining the ((->) a) instances for type classes like Functor and Monad 'cause I don't really get them still.

giogadi
Oct 27, 2009

rrrrrrrrrrrt posted:

Does someone want to take a stab at explaining the ((->) a) instances for type classes like Functor and Monad 'cause I don't really get them still.

I would also like to see this.

sink
Sep 10, 2005

gerby gerb gerb in my mouf

Barnyard Protein posted:

Math articles on wikipedia read like they were written by someone jacking off to how much smarter they are than everyone else. I guess it is supposed to be a reference, not a text book, but Its hard to find math text books that aren't too advanced or too basic.

I'm trying to relearn modern algebra, this book is excellent in terms of being fast paced without assuming too much about how much you already know. http://www.amazon.com/gp/product/0486474178

I just ordered this, thank you. I've heard good things about Algebra 0.

I've started Algebra of Programming and it is very, very good. Harder to find though.

gonadic io
Feb 16, 2011

>>=

rrrrrrrrrrrt posted:

Does someone want to take a stab at explaining the ((->) a) instances for type classes like Functor and Monad 'cause I don't really get them still.

Short answer: Don't use them.

Long answer:

For functor, fmap is (.). I've not yet found a case where this is useful per say, but it's a thing.

Due to (subject to a slight renaming of the variables)
code:
fmap :: (b -> c) -> f b -> f c
-- replace f with ((->) a)
fmap :: (b -> c) -> ((->) a b) -> ((->) a c)
-- make (->) infix
fmap :: (b -> c) -> (a -> b) -> (a -> c)         -- exactly the type of (.)
For monoids (this one is actually slightly useful), the instance is:
code:
instance Monoid b => Monoid (a -> b) where
    (<>) :: (a -> b) -> (a -> b) -> a -> b
    f <> g = \a -> f a <> g a
I've used this when defining custom Ord instances using Down (which reverses Ord instances). For example, I had a solution type where I was maximising the value, then if there were two solutions with equal value I wanted the one with the lowest weight to win.

code:
data Solution = Solution {value :: Int, weight :: Int}
    deriving (Eq, Show)
instance Ord Solution where
    compare = comparing value <> comparing (Down . weight)
Basically it saves you a few characters and that's it.

As with the monad instance, I'm not entirely sure - let's work out the types now (again, subject to the renaming):
code:
class Monad m where
    return :: b -> m b
    (>>=)  :: m b -> (b -> m c) -> m c
    join   :: m (m b) -> m b

-- replace m with ((->) a)
instance Monad ((->) a) where
    return :: b -> ((->) a) b
    (>>=)  :: ((->) a) b -> (b -> ((->) a) c) -> ((->) a) c
    join   :: ((->) a) (((->) a) b) -> ((->) a) b

-- make (->) infix and remove unneeded brackets
instance Monad ((->) a) where
    return :: b -> a -> b
    (>>=)  :: (a -> b) -> (b -> a -> c) -> a -> c
    join   :: (a -> a -> b) -> a -> b

-- let's guess the implementations based on the fact that we only have one thing
-- of any given type
instance Monad ((->) a) where
    return b = \a -> b             -- return = const
    f >>= g  = \a -> g (f a) a     -- not really sure how this'd be useful
    join f   = \a -> f a a         -- duplicate an argument for a function
Bear in mind that ((->) a) is the Reader monad, i.e. the "context" is that all values in the monad have access to a value of type a.

In short, I've used (<>) and join for functions, and only to save a few characters in common use cases.

One concrete use for join is, using Debug.Trace.traceShow (which bypasses the type system to print a value):
code:
traceShow      :: Show a => a -> b -> b
join traceShow :: Show a => a -> a
I.E. print a value as it passes through your code.

e: and let's just not talk about the function `fmap fmap fmap', also known as (.:) or (.).(.) or the boobs operator (which I have used more than the other mentioned functions here put together. I'll leave it as an exercise to figure out its type and what it does)

gonadic io fucked around with this message at 22:05 on May 8, 2015

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

As for when you'd actually use the monad instance for (-> r), the idea is you can have a single value that's implicitly passed to many different functions. What you'd actually use if you want this idea is the Reader monad.

sarehu
Apr 20, 2007

(call/cc call/cc)
You mean ((->) r).

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

Yes.

VikingofRock
Aug 24, 2008




So apparently facebook is re-writing their content classification code in Haskell. Pretty interesting to see the language in use by one of the bigger tech companies around!

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Yeah, that system is in production now. They had to force an eager approach to some data handling to avoid catastrophic runtime overload, recently: http://www.serpentine.com/blog/2015/05/13/sometimes-the-old-ways-are-the-best/

AWWNAW
Dec 30, 2008

Subjunctive posted:

Yeah, that system is in production now. They had to force an eager approach to some data handling to avoid catastrophic runtime overload, recently: http://www.serpentine.com/blog/2015/05/13/sometimes-the-old-ways-are-the-best/

Asil Ching says:
2015-05-13 at 22:50
What the gently caress you are talking about man? Can you write a few lines that shows some education? Thunk your rear end you punk show off.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

AWWNAW posted:

Asil Ching says:
2015-05-13 at 22:50
What the gently caress you are talking about man? Can you write a few lines that shows some education? Thunk your rear end you punk show off.

Well, he has a point.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Subjunctive posted:

Yeah, that system is in production now. They had to force an eager approach to some data handling to avoid catastrophic runtime overload, recently: http://www.serpentine.com/blog/2015/05/13/sometimes-the-old-ways-are-the-best/

its pretty ace

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
There was an interesting talk/paper about that querying/parallelising/caching infrastructure given at ICFP last year: https://www.youtube.com/watch?v=jG9PWdV1wso

bobthenameless
Jun 20, 2005

Barnyard Protein posted:

I'm trying to relearn modern algebra, this book is excellent in terms of being fast paced without assuming too much about how much you already know. http://www.amazon.com/gp/product/0486474178

I ended up buying this from your recommendation, and it (and some other mathy/cs books) just arrived today. Thanks for it, it looks really great so far

VikingofRock
Aug 24, 2008




Speaking of interesting math-y books, can anyone recommend a good book on category theory? I've been meaning to read up on it more.

sarehu
Apr 20, 2007

(call/cc call/cc)
Category theory is a waste of time.

gonadic io
Feb 16, 2011

>>=

sarehu posted:

Category theory is generally a waste of time if you are trying to get better at functional programming

ftfy

VikingofRock
Aug 24, 2008




I'm not really interested in reading it for functional programming purposes--I just thought this thread would be a good place to ask since there is an overlap between the two subjects.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

VikingofRock posted:

Speaking of interesting math-y books, can anyone recommend a good book on category theory? I've been meaning to read up on it more.

Don't know how I've seen this recommended. I read the first two posts and it seemed pretty good.

xtal
Jan 9, 2011

by Fluffdaddy
I don't know if any other functional programmers run into this problem, but I have a really hard time deciding which language I want to use for new projects. My two main choices are Racket and Haskell. I think that Racket programs can be developed much faster because of the minimal syntax, dynamic typing and macro system. But they're less safe than Haskell programs, which have static typing and pure functions.

Are there any languages that are a compromise between the two, like a statically-typed, purely functional Lisp language? I'm trying to get into Typed Racket and I figure I could use the monad library for side effects. The benefit I see is that I can start with an untyped program and add types as needed.

xtal fucked around with this message at 22:55 on May 18, 2015

sarehu
Apr 20, 2007

(call/cc call/cc)
I've used both, Haskell is faster because it has good syntax, static typing, and is advanced enough that it doesn't need to resort to a macro system to do basic programming tasks.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


VikingofRock posted:

Speaking of interesting math-y books, can anyone recommend a good book on category theory? I've been meaning to read up on it more.

I haven't looked too deeply at either of them, but I hear good things about Conceptual Mathematics and Category Theory for the Sciences.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

xtal posted:

I don't know if any other functional programmers run into this problem, but I have a really hard time deciding which language I want to use for new projects. My two main choices are Racket and Haskell. I think that Racket programs can be developed much faster because of the minimal syntax, dynamic typing and macro system. But they're less safe than Haskell programs, which have static typing and pure functions.

Are there any languages that are a compromise between the two, like a statically-typed, purely functional Lisp language? I'm trying to get into Typed Racket and I figure I could use the monad library for side effects. The benefit I see is that I can start with an untyped program and add types as needed.

Maybe it's because I've hardly used Racket, but I certainly don't find that programming in dynamically typed languages is faster.

Athas
Aug 6, 2007

fuck that joker
I have never used Racket, but I have written 10000+ SLOC programs in Common Lisp and 10000+ SLOC programs in Haskell. While Common Lisp is more powerful, I have come to prefer Haskell. If you sit down and think about your data structures in advance, the difference in power is not significant, and Haskell does give you more peace of mind.

You will, at times, curse some of the shortcomings of Haskell, just like you will curse the shortcomings of any language. But if you know Lisp, you would know that it could be fixed with proper macros. Yes, there is Template Haskell, but that is a horrible place, and you must never go there.

QuantumNinja
Mar 8, 2013

Trust me.
I pretend to be a ninja.
Template Haskell is, as a colleague put it, "the simplest possible thing that could work". It's got a horrible notion of hygiene, a bad interface, and a frankly unfortunate usage pattern. The paper is also a jumbled mess of "but it's like C++ templates", instead of just admitting that they really want syntax-case but don't want to try to get that together and working.

Adbot
ADBOT LOVES YOU

VikingofRock
Aug 24, 2008




I've been thinking about implementing Conway's Game of Life in Haskell. Does anyone have any recommendations for graphics libraries to use?

  • Locked thread