• Categories
    • Unread
    • Recent
    • Popular
    • Users
    • Groups
    • Register
    • Login
    1. Home
    2. Almost
    3. Topics
    Offline
    • Profile
    • Following 0
    • Followers 2
    • Topics 44
    • Posts 259
    • Groups 1

    Topics

    • AlmostA

      Accidental Emoticons

      Watching Ignoring Scheduled Pinned Locked Moved The lounge
      2
      2 Posts
      99 Views
      theDaftDevT
      aLc = A soldier with a rifle and a mic. Source: bf3
    • AlmostA

      Android Keyboards

      Watching Ignoring Scheduled Pinned Locked Moved Tech
      2
      2 Posts
      1k Views
      ScuzzS
      I was using the stock keyboard for Cyanogen Mod, I dont know what it is but it is pretty bad. I found that it predicted what i wanted but would not auto correct my words. I stuck it our for a while thinking it was just my fat finger typing but switching to Swift Key has been a massive improvement. I would suggest you try Swift Key. The predictions are great and i can type as fast as i can without many mistakes. The only mistakes I have are when i try and type slang or some word that isn’t real it auto corrects to an actual word. It also has that swipe thing too.
    • AlmostA

      Game Night (Terraria? Dinosaurs in Minecraft?) [Friday, July 3rd]

      Watching Ignoring Scheduled Pinned Locked Moved Gaming game night
      8
      8 Posts
      963 Views
      ScuzzS
      was this another failed attempt?
    • AlmostA

      [I/O 2015] Developer Tools

      Watching Ignoring Scheduled Pinned Locked Moved Tech developer tools google io
      1
      1 Posts
      316 Views
      AlmostA
      Developer Tools I won’t be spending much time on this one as it’s mostly technical and mostly minor. Instead, I’ll just give you a quick list of notable features. Android Studio Faster Gradle builds New memory profile Full editing/debugging for C++ Polymer 1.0 full release new elements does anyone even care? iOS CocoaPods for dependencies Testing Cloud Test Lab Search App Indexing puts apps into search results Google Cloud Messaging iOS support Topical subscriptions (i.e. channels) Web Web push notifications Webapps on android homescreen Universal App Campaigns Set your budget and let google advertise for you Google Play Increased statistics Experimental listings (test how different graphics affect downloads) Developer pages (A homepage for all your apps)
    • AlmostA

      [I/O 2015] Google Cardboard

      Watching Ignoring Scheduled Pinned Locked Moved Tech google io google cardboar
      1
      1 Posts
      256 Views
      AlmostA
      Google Cardboard It may seem odd for google to talk about updates to an ultra-cheap VR headset that was announced in passing at the end of last year’s I/O. At the time, it seemed like a fun little thing that Google wouldn’t follow up on and after 6 months and a handful of apps, it seemed like that was exactly the case. However, towards the end of last year, Google announced a new Unity sdk for writing cardboard apps. Additionally, they added a Cardboard compatible section to Google Play and introduced a Google Cardboard certified program for officially supported, 3rd party viewers. This made it clear that google actually plans to take cardboard further. I wouldn’t be surprised if eventually there were more premium models. At there were really two interesting things. A new version of Cardboard A new camera rig for 360 degree video. New version of cardboard Supports phones up to 6" New input button (not a magnet any more) iOS support Nothing here is that groundbreaking. Just more compatibility. Jump More interestingly, google announced an open source hardware design for a rig to shoot 360 degree videos. The whole project, called Jump, has 3 parts Custom camera rig Assembler Viewer Custom rig The custom rig consists of 16 cameras arranged in a circle which geometry that google claims is the best for stitching later. The design for the rig will be out there for anyone (but probably mostly companies) to build and play with. Additionally GoPro will be working with google to bulid and eventually sell a Jump ready rig that will handle the synchronization of the streams, exposure control, etc. Go Pro Rig: [image: 3pwoKPU.png?1] Assembler In order to actually get a 360 degree video, those 16 camera feeds obviously need to be stitched together. This is extremely expensive. “1000s of computers” says google. Google will be making it’s assembler available to a hand picked group of video makers this summer. It sounds like they will eventually make it available more broadly, but it was not entirely clear, although an open camera design seems weird if you need a google-scale assembler that you don’t have access to. We’ll have to wait and see. Viewer Lastly, in order to actually watch the videos, you need a viewer. Where would you watch videos related to Google? YouTube, of course. Youtube has already added a 360 degree video section on at least the Android App. You can watch the video and use your phone as a view port into the center of the scene. It feels a lot like a video version of a photosphere (I guess because it literally is…). It’s a neat little thing, although it’s not the VR I would expect. However, the keynote seemed hopeful. Clay Bavor kept using the term “VR Video” and talking about “stereoscopic video.” Therefore, we should expect to eventually see Cardboard-enabled video on YouTube, and then we’ll truly be able to step into the scene.
    • AlmostA

      [I/O 2015] Google Photos

      Watching Ignoring Scheduled Pinned Locked Moved Tech google photos google io
      1
      1 Posts
      269 Views
      AlmostA
      Google Photos A brand new product. Not to be confused with Picasa or Google+ Photos, those were totally different, guys. The logo is a pinwheel not an aperture [image: agwawweg.png] All jokes aside, Google Photos is a rather creepy extension on Google’s previous photo apps. In an exaggerated recount of the hundreds of pictures taken of his daughter’s kindergarten graduation, Anil Sabharwal points out a legitimately large flaw in our culture of documenting everything: organization. With thousands of pictures, we struggle to find that specific on from that one time 3 years ago. What to show someone the essence of your trip to the moon last weekend? Good luck finding a good representation! Sharing that album of all the mediocre food you’ve had in the last year is tricky when your friends are on instagram and you’re still on flickr. Google Photos addresses these shortcomings with 3 stated goals: To be a Home for all your photos & videos To automatic organize your photos Be easy to share and save (i.e. cross platform) Home In order to be a home for your media, Google is offering unlimited storage of High Quality photos and videos.* It’s not hard to see the implications of that much free† storage. * up to 16 megapixel pictures, 1080p video † “free” Organization Of course, just having storage is no better than our current solutions, but that’s where automatic organization comes in. Of course, starting out obviously, Google Photos can give you a timeline of your photos. By default, it will show highlights for individual days, however with standard zooming gestures, you can view by months or years. [image: z3JGOGs.png?1] [image: e7uL0Fh.png?1] [image: ENufyye.png?1] Where Google Photos truly shines (and becomes creepy) is in it’s more data-oriented aggregation: your photos will automatically be organized by people, places, and things: [image: HHqQ5WG.png?1] Google uses is image analysis expertise to make categories of your personal photos with, from what I’ve seen, surprisingly accurate results. Not only will it find all pictures of the same person, the thumbnail for it will be the best headshot of that person. People can even be recognized over time - all the way back to their baby pictures (that’s some crazy recognition). Is there a car in the background of your photo? You better believe that’ll show up if you search your pictures for “cars.” Snow? Yup. All knowing Google, mirite? Sure would make it easy to keep track of your nudes ;) Sharing In order to make sharing hassle free, you generate a link for an arbitrary collection of your photos and send it to your friend. Your friend can then view these photos on the internet without having to have any apps or be logged in to any services. If your friend is also on Google Photos, they will have a one button import, making it simple to send and receive photos for permanent storage. Sure would make it easy to leak your nudes ;) Editorial There’s no doubt that Google Photos is impressive and probably quite useful, but it brings up a privacy question - what is google doing with my photos? Obviously, they’re going to use it to improve train their image AI. But is that it? The audiences nervous, half-hearted clapping indicated that people are a little skeptical of this new service. But is it really that different? We already give Google a shocking amount of personal data. The visibly personal aspects of photos make it much more obviously invasive, but is it really significantly different information than before? I think it could be argued either way. Whether you buy into Google’s vision for you photos or not, you have to admit that their AI is really good.
    • AlmostA

      [I/O 2015] Now on Tap

      Watching Ignoring Scheduled Pinned Locked Moved Tech now on tap google io
      1
      1 Posts
      233 Views
      AlmostA
      Now on Tap Google now has been fairly good at location-based contextual awareness - what’s the weather? How long will it take to get to work? At the airport - where’s my boarding pass? All answered before you ask the question. More recently, Now can bring apps into the mix - At the airport -> order an uber. On the train -> here’s your music. Now on Tap takes that a step further and adds contextual awareness within apps. E.g. Listening to Skrillex? Ok Google, what’s his real name? - Sonny John Moore. E.g. Friend references a movie in an email? Hold home button and information about the movie shows up E.g. SO asks you to order dinner and pick up the drycleaning? Hold home button to get the restaraunts menu and set a reminder to pickup the drycleaning. [image: FaV9bNU.png?1] From the looks of it, Now on Tap can use your dynamic context to aid in searching. At the same time, they talk a lot about “indexing your app” which makes it sound like google now is using static information in your app. Or maybe your app exports context. It’s not entirely clear. Overall, Now on Tap builds upon Google’s contextual awareness by integration with 3rd party apps.
    • AlmostA

      [I/O 2015] Brillo & Weave

      Watching Ignoring Scheduled Pinned Locked Moved Tech brillo weave google io
      1
      1 Posts
      282 Views
      AlmostA
      Brillo & Weave Of course, Google introduced it’s attempt to get into the automation game with Brillo, an android-based IoT OS, and Weave the communication protocol that will make it all work. Nest’s, err, Google’s ambitions go beyond the home and extend to larger things such as farm irrigation equipment, or even a cities public transportation. Brillo Brillo is a simplified Android OS for use in internet connected appliances. Pichai talks about door locks with enough computing power for WiFi and BLE. Oddly high powered devices for such a specific task. Weave Weave is the communication protocol Nest Google will use (too many standards? Make a new one!). This will take the form of a moderated schema that will define common actions across devices, making it sound much like Android’s current intent system. Of course, Android devices will natively support weave, but it will be cross platform. This looks standardized, right?? [image: 8NF5dR2.png?1] Coming Q4 2015. Yeah. That’s literally all the info we got.
    • AlmostA

      [I/O 2015] Android Wear

      Watching Ignoring Scheduled Pinned Locked Moved Tech android wear google io
      1
      1 Posts
      223 Views
      AlmostA
      Android Wear This is the part where I rage. Following the lead of Apple’s rediculously complex watch, Google too has fallen to the “Your watch can replace your phone” trap that they did a good job of avoiding last year. Despite their claim that glanceability dominated their thoughts, this year, Wear is not about more context, but more interaction. Launchers, gestures, Wi-Fi, and Bluetooth dominated over glances and hints. With Google Now’s goal of knowing what you need before you need it, I find this an unacceptable approach. No one wants to text on their watch. But hey, at least Android Wear isn’t fragmented. Always On Apps Please tell me real apps won’t look this bad. [image: Image%202015-06-19%20at%209.47.29%20PM.png] The time is not the only thing that can be persistent on your wrist. After launching an app, it will always on in a balck and white mode. It looks pretty awful. Wrist Gestures You can now “naturally” jerk your wrist around to navigate. It’s just awful. (Sorry the gfy is so huge) https://gfycat.com/ComfortableShamelessGermanshepherd Emoji Recognizer Draw emoji. OOOOooohh AAaaaAhhhhhhHHh [image: pEk4LiU.png?1] [image: Mtzl5uE.png?1] Fucking really? Launcher Vertical launcher. You can now scroll vertically to find facebook messenger to draw a fucking cocktail glass to send to Alice. “Ultimately, wearable apps should be glanceable, actionable, and effortless.” And that’s why we added a fuck ton of awkward interactions so you can spend more time interacting with your wrist than forgetting about the technology and staying in the moment. “Using Spotify, you can browse and control the music you want to hear.” “And on your way home, you’ll be able to adjust your living room temperature with nest” Shut the fuck up google. You’re going to ruin this the same way you ruined Glass by focusing on the camera rather than the HUD.
    • AlmostA

      [I/O 2015] Android M

      Watching Ignoring Scheduled Pinned Locked Moved Tech android m google io
      1
      1 Posts
      199 Views
      AlmostA
      Android M Well, we know it won’t be called Milkshake… [image: Google-IO-2015-_0519.jpg] Android M’s addition to Android is mostly standardization, integration, and simplification. It’s not as much about new, flashy features as it is about making things work better and with less cognitive effort on the part of the user. Permissions [image: Image%202015-06-19%20at%209.04.23%20PM.png] App permissions are (finally) no longer all or none. In old version of android, before you could install an app, a dialog popped up asking you to agree to an onslaught of permissions that the app needed. For apps like Facebook that literally would buy your soul if it could, this comes out to 12+ permissions. Your choices were agree to them all, or don’t use our app. Basically Android peer pressured you into giving away your security and privacy. The “new” model has only 6 permissions: Location, Camera, Mic, Contacts, Phone, SMS, Calendar, Sensor In addition, apps no longer ask you to agree to them all at install time. The first time an app uses a permission, you are prompted as to whether you want to grant that permission. If you deny it, the app will not be able to use the permission. No longer is it all or none. Above, I said “new” in quotes for a reason. This isn’t really a fundamental change to the Android permssioning system, but rather a change to how the user perceives it. From a developers perspective, an app must request the exact same permissions in M as in any previous version. Instead, the user is prompted differently (at runtime, not install time) to grant the permissions. Apps targeting old versions of the app will simply use the old install-time prompt. An astute reader may have noticed an interesting omission in the list of permissions: Internet. Yes, that is correct, an app no longer needs to ask you for permission to access the internet. This may seem like a glaring omission (why the fuck would a flashlight need internet access?), but the Android team has clarified it as unnecessary. Since everything else is guarded behind a runtime permission request, an app with only internet can’t leak your data. While true, this is a little bit unnerving - could a flashlight use an exploit to leak data and upload it without you even knowing it is accessing the internet? I’m not entirely convinced this isn’t an issue, but it is a fairly minor one, at least. Chrome Custom Tabs In an interesting attempt to blur the lines between native and web apps, google introduced branded, custom chrome tabs. Pinterest App [image: Image%202015-06-19%20at%209.20.00%20PM.png] Pinterest Custom Tab [image: Image%202015-06-19%20at%209.20.27%20PM.png] The idea is that when a link is clicked from your app, rather than having to implement your own webview or do a full context switch to the web browser, you can embed open a branded chrome tab. This has the benefit of being faster than switching to the browser and retaining most of the feel of your app. To make it truly fast, the web content can be prefetched to allow native-like transitions (It was not clear if every link is prefetched). App Linking Along the same lines of Chrome Custom Tabs, Android M is blurring the line of native and web apps on the native side. If you’re familiar with Android Dev, there is a concept of an intent. An app can advertise that it can handle, say, document editing intents. Then, a different app can send out an intent to edit a document which then opens in the first. This is how you can click the share button and see a bunch of installed apps to share with. One of the issues is that if you open, say, a youtube link, Android will ask you whether to open it in the YouTube app or Chrome. To enhance this, apps can claim full ownership of links. Basically the app claims links to youtube. When you install the app, Android will go to youtube and look for a file containing the signature of the app. If it finds it, Android will automatically open youtube links in the youtube app without asking for user input. Apps can claim links to avoid the disambiguation dialog Android Pay Really isn’t much to say. This is Google Pay moved into Android rather than as a google app. On interesting thing is that when you add a card to Android Pay, it get’s a fake credit card number that is shared with the merchant. If an sketchy merchant abuses your info, you can just remove the card from google pay and the merchant has no access anymore. Fingerprint Standardized. Expect more phones with fingerprint readers (also easier access for devs) Doze Basically, when you don’t use your phone, wake ups for background tasks are take on exponential back off. Google claims up to 2x battery life in standby, which largely means if you leave your tablet on a shelf or don’t plug your phone in overnight, it won’t die. Kinda cool, mostly meh. Misc USB-C standard Text highlighting jumps to word boundaries forward (individual characters backwards) Lollipop volume controls are gone (back to the kind that actually fucking works) Dev preview is available on Nexus 5, 6, 9, player
    • AlmostA

      [I/O 2015] Overview

      Watching Ignoring Scheduled Pinned Locked Moved Tech overview google io
      1
      1 Posts
      200 Views
      AlmostA
      Google I/O 2015 Overview Hey guys! I’m back once again with another I/O recap! (See the 2014 keynote here) So, I/O was actually like 3 weeks ago, but due to the combination of me being lazy and an underwhelming keynote, I struggled to actually get to reporting on it. Compared to the excitement of last year’s keynote, I/O 2015 was bland and, at points, frustrating. This year’s keynote was mostly about incremental updates with the improvements we expected only a few (actually kind of creepy) things we didn’t expect. We, predictably, heard about updates to Android, Cardboard, Wear, and developer tools. We Predictably heard about Google’s (Nest’s) entry to the smart home market. We somewhat predictably heard about an update to Google Now. And we surprisingly heard about a creepy Google Photos (minus google+). Overall a lukewarm review of the companies less-than-thrilling, yet still necessary achievements. For a full (read: editorialized) recap of each, check out the threads below. Android M Android Wear Brillo/Weave Now on Tap Google Photos Google Cardboard Developer Tools
    • AlmostA

      Gamertag Thread

      Watching Ignoring Scheduled Pinned Locked Moved Gaming
      2
      2 Posts
      362 Views
      SchamperS
      @Schamper: Schamper
    • AlmostA

      [spoilers] Monument Valley

      Watching Ignoring Scheduled Pinned Locked Moved Gaming
      2
      2 Posts
      487 Views
      ScuzzS
      Link for the lazy It’s currently £0.49 on the UK Play store.
    • AlmostA

      [Challenge] BB Gets Drunk

      Watching Ignoring Scheduled Pinned Locked Moved Development and Coding
      3
      3 Posts
      572 Views
      AlmostA
      Really minor improvement, but in order to remove that extra if (numStillWanted > 0) we could consider any alcohol that we don’t have as inventory that belongs to no one. To make this work in the code, we just add a line outside the outer loop: have = have.concat(wanted.select(cur => new AlcoholInventoryItem(null, cur.Name, cur.Quantity)); With this, we’re assured that we will never be left with numStillWanted > 0 after the inner loop because in the case where no one has any of the alcohol we want, our inventory consists of alcohol that belongs to no one that has exactly the quantity we want.
    • AlmostA

      Norwegian Wood

      Watching Ignoring Scheduled Pinned Locked Moved The lounge norwegian wood haruki murakami
      6
      6 Posts
      756 Views
      LyetaL
      I didnt read it or watch movie I didnt even know it existed till just now Your challenged your bs call and read whole damned post >> And i dun wanna read this book now or watch movie x.x
    • AlmostA

      [No Spoilers] House of Cards Season 3 Live

      Watching Ignoring Scheduled Pinned Locked Moved The lounge house of cards
      4
      4 Posts
      678 Views
      SchamperS
      @Almost that’s how I felt when reading this while watching HoC season 3.
    • AlmostA

      A Brief Introduction to Haskell

      Watching Ignoring Scheduled Pinned Locked Moved Development and Coding haskell
      1
      1 Posts
      409 Views
      AlmostA
      A brief introduction to Haskell So, what I really wanted to do was to make a post about how functional programming concepts are useful after a discussion that came up in the shoutbox over my suggested use of a function as the second argument of string.replace in @Scuzz’s omdb plugin thread, but I realized that some of the more subtle examples are hard to show without rigorous syntax. So, I thought I would use this post to outline a bit of Haskell syntax which will touch on some functional concepts and lay the ground work for understanding examples in a later post arguing the utility of functional programming. DISCLAIMER: I’m not an expert in Haskell, nor have I built any real software with it, so forgive me if I remain in the conceptual domain So, here we go! First, if you want to play around with Haskell, it seems the go to is the Glasgow Haskell Compiler (GHC). Check out the Installation page at haskell.org (P.S. on mac brew install ghci) Maths Arithmetic As with all of our favorite interpreted languages, we can sit at the interpreter and do math all day: > 2 + 4 6 > 2 * 4 8 > 2 ** 4 -- 2 ^ 4 (line comments in Haskell begin with --) 16.0 Great, so we know we have some predefined types and operations (technically speaking in the manner we’ve presented above, those literals are not primitives; they are actually boxed, but we’ll get there in time). To exit the interpreter, use :quit Variables Like other languages, we can bind an expression to a name. > let x = 10 > x 10 Variables MUST begin with a lowercase letter. Unlike other languages, we cannot modify the value of x in a literal sense. We can rebind x, but this will create a new object rather than updating the old one. This leads to an important result: > let x = 10 > x 10 > let x = x + 10 > x In our favorite imperative language, we would expect to see the value of x updated to 20. However in Haskell it doesn’t evaluate. Why? because we have defined x in terms of itself. If we try to expand it, we get x + 10. Expand that, we get x + 10 + 10. If that doesn’t make sense, think about it this way: what we said is “where ever you see x replace it with x + 10”. Now, if I asked you “what is x?” here, you can only answer “x + 10” As you can see, this can never resolve to a value. Functions Of course, we can write our own math functions > let addOne x = x + 1 > addOne 1 2 The syntax for defining a function is let <function name> <variables> = <expression> The syntax for calling is just <function name> variables. Function names MUST begin with a lowercase letter. The interesting thing in Haskell (as well as other functional languages) is that functions are first-class citizens, meaning they can be treated like any other data. This allows us to do things like pass functions as arguments. > let square x = x * x > let applyTwice f x = f (f x) > square 2 4 > applyTwice square 2 -- (2^2)^2 16 This is obviously a contrived example, but it shows that we can pass a function and then call that function. Loading Haskell files Ok, before we go any further, lets get off the cumbersome interpreter. A lot of future example code will be in files. When you see the ‘>’ you’ll know I’ve switched back to the interpreter, but just to make it clear, I’ll always show myself loading the file in question e.g. -- add.hs add x y = x + y -- Function declaration syntax in a file (no need for let) > :load add -- load syntax (leave off the .hs) [1 of 1] Compiling Main ( add.hs, interpreted ) Ok, modules loaded: Main. > add 2 4 6 Data Custom Data Types So at this point, we know how to do stuff with built in types declare variables declare and invoke functions load code from a file Next, we would like to be able declare our own data types, much like being able to define our own classes. For this section, we will be implementing our own Bool type which we’ll call Loob with values Yes and No -- loob.hs data Loob = Yes | No data types MUST begin with a capital letter, like how functions must be lowercase. What did this actually do, @Almost? This defines a new data type, Loob with 2 data constructors, Yes and No. There isn’t a good equivalent to a data constructor in imperative languages, but the easiest way to think about it is kind of like an enum. We will see later how this notion isn’t quite right. enum Loob { Yes, No } Let’s take a look at our new type. > :load loob > let x = Yes > x Yes > :type x -- Gets type information from a variable x :: Loob -- Format: <name> :: <type> The let x = Yes statement instructs the interpreter to use the Yes data constructor to instantiate a new Loob and assign it to the variable x. Meaning the data of x is now Yes and the type of x is now Loob. In imperative space this is kind of like Loob x = Loob.Yes Going back to loob.hs, let’s define our own and function which we’ll call dna. -- loob.hs data Loob = Yes | No dna Yes Yes = Yes dna No _ = No dna _ No = No > load loob.hs > dna Yes Yes Yes > dna Yes No No > dna No Yes No > dna No No No This example shows off a couple of important points in Haskell. Functions can take arbitrary parameters the _ in the function definition means “any argument” in can be any type, any value, we don’t care. We know that No and Anything is always No, so we don’t even need to look at the second argument. This does have the side effect that dna No 1234 is defined as No which may or may not be desirable. Since we don’t give _ a name, we can’t use it in the body of our function. It literally means “I don’t need to know, nor even care what this data is” Functions can have multiple definitions over the same argument data type It might be hard to see what I mean due to the usage of _ but we could have written out all the cases explicitly: dna Yes Yes = Yes dna No Yes = No dna Yes No = No dna No No = No In an imperative world, this should be alarming. We just overloaded dna 4 times and each one takes 2 Loob arguments! If I were to calls: > let x = No > let y = Yes > dna x y How should it know which of the 4 functions to use? This is where our enum notion falls apart. Haskell uses the data constructor for the variables to perform pattern matching to find the first definition that matches the input. therefore our example above explicitly matches the 2nd definition for dna, so that one will be used. While defining our own pseudo primitives is nice and all, can we define actually useful types, like say Pair? Sure. While we didn’t take advantage of it before, our data constructors can act as a tag for other data: -- pair.hs data Pair t = Pair t t -- Declare data type Pair of t (where t is an arbitrary type). You might write this as Pair<T> in C++ or Java left (Pair x y) = x right (Pair x y) = y Don’t be confused here. I’ve named both the data type and data constructor “Pair”. in our functions, left and right, the argument is weird. That looks like how we construct a Pair doesn’t it? That’s exactly what it is. Haskell’s pattern matching basically says “Could I use this syntax to construct the object that you gave me? If yes then we have a match, if not we don’t have a match” To try it out: > :load pair > let p = Pair 1 2 > left p 1 > right p 2 Lists Haskell’s list syntax is similar to that of python: > [1,2,3,4] [1,2,3,4] Haskell, however, has syntax to create a list over a range: > [1..10] [1,2,3,4,5,6,7,8,9,10] One interesting fact about Haskell lists, due to the fact that Haskell performs lazy evaluation, an infinite list is completely legal and will not cause a crash or hang unless you attempt to evaluate the whole list: > let x = [1..] > -- no crash :) Accessing an element of the list can be done with the !! operator. > let x = [1..] -- infinite list > x !! 9 10 -- 0 indexed Remember, the lazy evaluation means that only as much as is actually used is evaluated which means that indexing an infinite list is completely legal. Given a list, you can prepend it with the : operator > let x = [2,3,4] > 1:x [1,2,3,4] This is handy since we can use this list building syntax as a pattern in a function (as we discussed in the last section) > let head (x:xs) = x -- x is the first element, xs is the rest of the list > head [1,2,3] 1 > let tail(x:xs) = xs > tail [1,2,3] [2,3] What we’re saying here is that the argument of head and tail is “Something (x) appended to a list (xs)” An aside, Haskell represents strings as lists of characters > head "Almost" 'A' :type Simple types I brought up :type discreetly in the custom data types section. You can learn a lot about how Haskell works by examining the output of :type. > :type 1 1 :: Num a => a Read: 1 has type (Num a) which reduces to a What this actually tells us is that: 1 is not a primitive, but rather of type a a is restricted to those types in the Typeclass Num That second point is similar to the concept of requiring that a generic type extends some known type in Java: public class Foo<? extends Collection> Other simple examples: > :t True -- :t works in place of :type True :: Bool > :t "Almost" "Almost" :: [Char] > :load loob -- from a previous example > :t Yes Yes :: Loob Function types we see some new syntax when we look at functions > let square x = x * x > :t square square :: Num a => a -> a Let’s ignore the point that a must be in the Num Type class and focus on the a -> a You can read this as a goes to a Meaning, square takes a variable of type a and returns a type a. As a concrete example, square can take an integer and return an integer. What’s the type of a function that takes 2 variables? > let add x y = x + y > :t add add :: Num a => a -> a -> a Hmm. a -> a -> a huh? “a goes to a goes to a?” I don’t get it. well, let’s apply some grouping to help us out. Let’s read it as a -> (a -> a) For now, trust me that this is better than (a -> a) -> a. I’ll explain why this is the case later. In this view, we read “a goes to (a goes to a).” Still a little fuzzy? Well, remember that a -> a means that it’s a function that takes an a and returns an a. Therefore a -> (a -> a) should mean that it’s a function that takes an a and returns a function that takes an a and returns an a. But that doesn’t make sense. Add takes 2 numbers and returns one number. It doesn’t take 1 number and return a function. Or does it? > :t (add 1) (add 1) :: Num a => a -> a Why did that work? Add takes two arguments god damn it! That should have given us an error! In imperative languages we’re used to the fact that a function that has two arguments requires that you supply two arguments when you call it (or at least that you specify default in the case of optional values such as int myFunc(int myInt, bool myBool = false)). Haskell has no such requirement. When we evaluate add 1 2 anywhere we see x we replace it with 1 and anywhere we see y we replace it with 2. Therefore add 1 2 is equivalent to 1 + 2 But what forces us to replace both x and y? Why can’t we replace just x? Why shouldn’t we call add 1 and get back 1 + y? > Because you can’t evaluate 1 + y, @Almost… Exactly. We can’t evaluate it until we are supplied with a y. So instead of trying to evaluate it, we just give that expression back and say “give me a y and I’ll evaluate this.” Gee, that sounds like a function, doesn’t it? Rather than just looking at the type, let’s try giving that new function a name > let addOne = add 1 > addOne 2 3 Woah. So it really does give us back a function. This magic process of partially evaluating functions is called Currying (Named after one Haskell Curry. The guy was a bit of a narcissist: he named both a programming language and a mathematical concept after himself.) Currying has a very useful property in that it naturally supports code reuse and encapsulation A simple contrived example: > let pow x y = y ** x --Yes, this is a bit backwards from how we usually think of pow > let square = pow 2 > let cube = pow 3 As you can see, it gives us a really simple way to build software without reinventing the wheel or writing many many lines of code. On a philosophical level, this makes it easy for us to show that cube is just a specific case of the more general pow. We don’t get such an obvious connection if we write cube as cube x = x * x *x. Now. An astute reader might be thinking: isn’t it kind of weird that we have 2 ways to evaluation functions: fully and partially? Actually this is not the case. There is only one way to evaluate a function: By supplying one argument. add 1 2 is not passing 2 arguments to add, rather it is actually evaluating as (add 1) 2 - apply 1 to add and the apply 2 to the resulting function. What implication does this have on how Haskell treats functions? In Haskell a function has exactly one input and exactly one output. Either or both of the input and output can be functions, but there cannot be more than one input or output. Now, before we wrap up our section on function types and currying, let’s talk about why we chose a -> (a -> a) instead of (a -> a) -> a. How do we read the second one? “add takes a function and returns an a”. This should be valid then: > add add clearly that doesn’t make sense, therefore (with all the handwaving I have in me :P) this is not a valid way to read that type signature. In the case where the argument truly is a function, Haskell will indicate that to us >let applyToOne f = f 1 > :t applyToOne applyToOne :: Num a => (a -> t) -> t Don’t be scared by t. This just tells us that the return type of the function f as well as applyToOne isn’t necessarily the same type as the type o the input to f e.g. > let equalsOne x = x == 1 > :t equalsOne equalsOne:: (Eq a, Num a) => a -> bool Conclusion tl;dr There is no tl;dr. Go read it. Whew. Rushed is probably a better word than brief. I hope that was reasonably easy to follow, and if not, please ask questions. I want to both help you understand and improve my own technical communication. If some sections make absolutely no sense even with some of my clarification, don’t worry too much. This stuff is very different from the usual “state-machine” style of programming that most of us are familiar with. But just because it’s different, don’t count it out. A lot of the concepts introduced in functional programming are making their way back into mainstream programming languages (e.g. Lambda Expressions, Nullable Types, LINQ). If you’re interested in learning more about Haskell, Learn You a Haskell for Great Good is the standard Textbook. It’s free online legally, so no need to go searching for it. Hope you enjoyed that. Help me improve this! <3 Almost
    • AlmostA

      Offers from Google Play

      Watching Ignoring Scheduled Pinned Locked Moved Tech
      2
      2 Posts
      577 Views
      ScuzzS
      You get sweet deals with Chromecast too.
    • AlmostA

      Gumwrapper Truth or Truth

      Watching Ignoring Scheduled Pinned Locked Moved The lounge
      175
      175 Posts
      39k Views
      theDaftDevT
      @Schamper said: Well if you classify downloading as stealing… Several Terabytes. What a fucking G
    • AlmostA

      Google Cardboard Unboxing & Review

      Watching Ignoring Scheduled Pinned Locked Moved Tech unboxing review google cardboar
      4
      4 Posts
      3k Views
      AlmostA
      Apparently Google is now taking Cardboard seriously again. Google updated their cardboard site, created a list of cardboard apps, and added a Unity SDK. All official as of today. Maybe I spoke too soon in saying this was not going to progress.
    • 1
    • 2
    • 3
    • 1 / 3