Profile

Scrapbook photo 1
Nicholas Vanderweit
Attends University of Colorado at Boulder
Lived in Colorado Springs
39 followers|6,322 views
AboutPostsPhotosVideos

Stream

Nicholas Vanderweit

Shared publicly  - 
 
While writing a simulation in Scala, I ran into an interesting programming exercise that was fun to implement in a functional style. I'd be interested to see how other people solve this.

Given an outcome of a uniform random variable X ~ U(0,1) and the probability mass function of a discrete random variable Y, compute a random outcome of Y.

So, you have random numbers in [0, 1), given to you by your standard library, and a mapping like ("heads" -> 1/3, "tails" -> 2/3), and you want to come up with a function to give you "heads" or "tails" with the right probabilities.

Here's my solution (in Haskell):
https://gist.github.com/nvanderw/5269152
+Ken Sheedlo +Sam Pottinger 
1
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
JavaScript with proper tail calls? I like what I'm hearing.
1
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
Got this error today while writing some code on the bus. Laughed out loud. Now GHC knows how I feel! +Connor Janowiak 

[1 of 1] Compiling Main             ( church.hs, interpreted )

church.hs:6:31:
    My brain just exploded
    I can't handle pattern bindings for existential or GADT data constructors.
    Instead, use a case-expression, or do-notation, to unpack the constructor.
    In the pattern: Church unwrapped
    In a pattern binding: Church unwrapped = church (n - 1)
    In the expression:
      let Church unwrapped = church (n - 1) in f . (unwrapped f)
1
Nicholas Vanderweit's profile photoJay Hendren's profile photo
4 comments
 
Oh, I see! I've done that before, but I never knew it was called pattern binding or pattern matching. Thanks nick!

also, I'm almost set to register for classes... I'm having trouble communicating with advisors and professors at the moment. I'm just hoping that my first semester back at school won't be something dumb like CSCI1300 plus a writing elective.
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
Here's my solution. I sure didn't anticipate writing this much Scheme.+Ken Sheedlo 
1
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
Linguistic nitpicking: I sometimes wish that there were a more appropriate demonym for "someone from the United States" than "American." The Spanish speaking world has "estadounidense," for instance.
1
Ken Sheedlo's profile photo
 
United-Statesian!
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
I wrote a library that lets you use some functional programming techniques from Python: among them, currying, infix operators, and easy function composition. Get you one! +Ken Sheedlo +Sam Pottinger 
1
Add a comment...
Have him in circles
39 people
Rianne Campbell's profile photo
Gabriel Paez's profile photo
Ben Weingarten's profile photo
Sadie Joy's profile photo
Fiona Pigott's profile photo
Andrew Pineda's profile photo
Sam Pottinger's profile photo
Natalie Berryman's profile photo

Nicholas Vanderweit

Shared publicly  - 
 
And then there are those days when you just write your own numbers.
1
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
I'm starting to think unsubscribing from all of the default subreddits and replacing them with more insightful ones was a great decision.
2
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
I was wondering how these would interact with each other and found just the article. +Ken Sheedlo 
1
Nicholas Vanderweit's profile photoKen Sheedlo's profile photoConnor Janowiak's profile photo
3 comments
 
Thanks for your insight?
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
Check it out, it's a version of top that lets you monitor power usage on laptops with Intel chips. Super useful.
1
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
Nothing like learning about a language by jumping head-first into its C foreign-function interface. Static typing makes some of the runtime value representations really fun (unit, false, and the nullary list are all the same value, for instance).
1
Add a comment...

Nicholas Vanderweit

Shared publicly  - 
 
I've started developing a web app for one of my classes using Yesod, and I'm finding it to be very interesting. It's clearly been designed from the ground up to utilize type safety as much as possible to save you from errors. For instance, there are template languages for HTML, CSS, and JavaScript, and all of these are turned into Haskell syntax at compile-time and typechecked. The storage backend is database-agnostic and uses some more advanced Haskell features (like GADTs with phantom types) to channel dynamically-typed data from the backend into meaningful types as soon as possible.

The framework focuses on abstracting away the potentially frustrating features by using template Haskell, combined with a few DSLs for doing things like creating views, defining routes, and creating schemas with Haskell types.
1
Nicholas Vanderweit's profile photoTod Hansmann's profile photo
7 comments
 
I didn't say that problem solving requires Haskell; I was pointing out that any programmer who actually cares about working on a Haskell-based project can just learn the language. I think you overestimate how hard it is to learn new paradigms. And you aren't doing yourself a disservice by learning fresh ideas. I probably come off as a zealot because I advocate for it, and I advocate for it because I think it is underappreciated. So I point out neat features and ideas here and there to show how they can be useful in both the theory and practice of computer programming.

I actually don't mind when people tell me they don't like the language for some specific reason (the most popular one being lazy evaluation making it difficult to reason about resource usage; much work has been done to rectify this problem). It's much more unfortunate that plenty of people out there just don't care to learn something new because, hey, Python's what people are using, why not use Python?

Obviously there are practical reasons not to use Haskell in certain situations. I'm not saying that it's the only language worth using. I'd just like people to know of the various ways it makes programs more reliable, and generally more fun to think about and write.
Add a comment...
People
Have him in circles
39 people
Rianne Campbell's profile photo
Gabriel Paez's profile photo
Ben Weingarten's profile photo
Sadie Joy's profile photo
Fiona Pigott's profile photo
Andrew Pineda's profile photo
Sam Pottinger's profile photo
Natalie Berryman's profile photo
Work
Occupation
Software Engineer
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Previously
Colorado Springs - Boulder
Story
Introduction
I'm a Computer Science major at the University of Colorado at Boulder who's passionate about mathematics, science, and their many applications. Beyond this, I am also a human being who likes politics, culture, language, and numerous other things.
Education
  • University of Colorado at Boulder
    Computer Science, 2010 - present
Basic Information
Gender
Male