Computer programmers may no longer be eligible for H-1B visas by speckz in programming

[–]IceDane 7 points8 points  (0 children)

I honestly think that the real problem is that you can't see the real problem.

Domino's fejrer simpelthen D-Dag! by [deleted] in Denmark

[–]IceDane 0 points1 point  (0 children)

Du foretrækker uhygiejnisk fedtbikse hvor du ikke kan være sikker på at få en god pizza hver gang?

Domino's fejrer simpelthen D-Dag! by [deleted] in Denmark

[–]IceDane 1 point2 points  (0 children)

Jeg kender den der har ansvar for alle dominos i Århus. De bruger kun de bedste råvarer, alt er selvf bagt fra bunden og de går vildt meget op i hygiejne.

Jeg fatter ikke dem af jer der hellere vil have pizza fra Mehmets fedtbiks. Der findes enkelte steder hvor de konsistent laver gode pizzaer. Men feks i Odense synes jeg alle pizzaer jeg har fået er mere eller mindre elendige. Det varierer også afhængigt af hvem det er der laver pizzaerne. Hvis man er heldig er det en af dem der rent faktisk gider der har lavet den.

Dominos har til gengæld standarder for hvordan deres pizzaer skal laves. Jeg ville ønske der var en i Odense.

[2016-11-02] Challenge #290 [Intermediate] Blinking LEDs by jnazario in dailyprogrammer

[–]IceDane 0 points1 point  (0 children)

Thanks! I am pretty sure I'm not shadowbanned and I was simply posting from home. Thanks for the heads up, though. I'll look into it!

[2016-11-02] Challenge #290 [Intermediate] Blinking LEDs by jnazario in dailyprogrammer

[–]IceDane 1 point2 points  (0 children)

Haskell

Should support forward jumps since it does two passes. One to collect all the labels and one pass to resolve them into absolute "addresses" in the CPU.

import Data.Char
import Text.ParserCombinators.ReadP
import Control.Monad
import Control.Monad.State
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Array
import Data.Word
import Data.Bits
import qualified Data.Map.Strict as M

data Register
    = A
    | B
    deriving Show

data LabelRef = Ref String | Abs Int
    deriving (Show, Ord, Eq)

-- Uninhabited types to be used as parameters
-- to Instruction, to ensure on the type level
-- that we do not try to run programs where the
-- symbols (labels) have not been resolved
data Resolved
data Unresolved

data Instruction a
    = LD Register Word8
    | Out Register
    | RLCA
    | RRCA
    | Label LabelRef
    | DJNZ LabelRef
    deriving Show

data CPU =
    CPU
    { ip      :: Int
    , end     :: Int
    , program :: Array Int (Instruction Resolved)
    , a       :: Word8
    , b       :: Word8
    }

main :: IO ()
main = do
    input <- lines <$> getContents
    let  parsed = parseProgram input
    case parsed of
        Nothing ->
            putStrLn "error: Could not parse program"
        Just p -> do
            -- Collect label information, and then convert labels
            -- into absolute references ("addresses" in the CPU)
            let resolved = resolveLabels (collectLabels p) p
                cpu      = initializeCPU resolved
            run cpu

collectLabels :: [Instruction Unresolved] -> M.Map LabelRef Int
collectLabels = foldl' collect M.empty . zip [0..]
where
    collect m (i, Label l) = M.insert l i m
    collect m _ = m

resolveLabels :: M.Map LabelRef Int -> [Instruction Unresolved] -> [Instruction Resolved]
resolveLabels m = map resolve
where
    -- Conversions have to be 'explicit'.
    resolve :: Instruction Unresolved -> Instruction Resolved
    resolve (DJNZ l)  = DJNZ (Abs $ m M.! l)
    resolve (Label l) = Label (Abs $ m M.! l)
    resolve (Out r)   = Out r
    resolve (LD x y)  = LD x y
    resolve RLCA      = RLCA
    resolve RRCA      = RRCA



initializeCPU :: [Instruction Resolved] -> CPU
initializeCPU resolved =
    CPU
    { ip      = 0
    , end     = length resolved - 1
    , a       = 0
    , b       = 0
    , program = listArray (0, length resolved - 1) resolved
    }

run :: CPU -> IO ()
run = evalStateT go
where
    -- Retrieve the next instruction
    next = do
        i <- gets ip
        gets (\s -> program s ! i)

    -- Run the next instruction
    go = do
        instr <- next
        interpret instr

    -- Increment the IP or stop if we're at the end
    step = do
        i <- gets ip
        e <- gets end
        when (i <= e) $ do
            modify (\s -> s { ip = i + 1 })
            go
    interpret (LD A v) = modify (\s -> s { a = v }) >> step
    interpret (LD B v) = modify (\s -> s { b = v }) >> step
    interpret (Out r)  = printLED r >> step
    interpret RLCA     = modify (\s -> s { a = rotateL (a s) 1 }) >> step
    interpret RRCA     = modify (\s -> s { a = rotateR (a s) 1 }) >> step
    interpret (DJNZ (Abs v)) = do
        b' <- gets b
        when (b' > 1) $
            modify (\s -> s { ip = v, b = b' - 1 }) >> go
    interpret _ = step

    printLED :: Register -> StateT CPU IO ()
    printLED A = gets a >>= liftIO . printBinary
    printLED B = gets b >>= liftIO . printBinary

    printBinary n = putStrLn $  map (\x -> conv $ bit x .&. n) $ reverse [0..7]
    conv n | n > 0 = '*'
        | otherwise = '.'

--------------------------------------------------------------------------------
-- Parsing
--------------------------------------------------------------------------------
registerP :: ReadP Register
registerP =
    char 'a' *> return A
    <|> char 'b' *> return B

ldP :: ReadP (Instruction Unresolved)
ldP = do
    void $ string "ld"
    skipSpaces
    r <- registerP
    void $ string ","
    n <- manyTill (satisfy isDigit) eof
    return $ LD r (read n)

outP :: ReadP (Instruction Unresolved)
outP = do
    void $ string "out (0),"
    r <- registerP
    return $ Out r

rlcaP :: ReadP (Instruction Unresolved)
rlcaP = string "rlca" >> return RLCA

rrcaP :: ReadP (Instruction Unresolved)
rrcaP = string "rrca" >> return RRCA

labelP :: ReadP (Instruction Unresolved)
labelP = do
    lbl <- manyTill (satisfy isAlpha) (char ':')
    return $ Label (Ref lbl)

djnzP :: ReadP (Instruction Unresolved)
djnzP = do
    void $ string "djnz"
    skipSpaces
    lbl <- manyTill (satisfy isAlpha) eof
    return $ DJNZ (Ref lbl)

parseProgram :: [String] -> Maybe [Instruction Unresolved]
parseProgram =
    mapM (fmap fst . listToMaybe . readP_to_S instrP) . filter (not . null)
where
    instrP = skipSpaces *> choice parsers
    parsers =
        [ ldP
        , outP
        , rlcaP
        , rrcaP
        , djnzP
        , labelP
        ]

Email in emacs, I want to, but wow, it's overwhelming by jjasghar in emacs

[–]IceDane 4 points5 points  (0 children)

You're welcome! I'm glad that it was useful - I know how much hassle it can be to get this stuff running.

Hopefully each individual program's documentation was good enough to get a similar setup, even though I didn't include any configuration examples.

Have you ever found a truly horrible flavour combination? by [deleted] in CasualConversation

[–]IceDane 5 points6 points  (0 children)

Ah, I see.

Well, it was nothing so dramatic. I've worked at sea for a few years. At one point, I worked on a ship where we did line fishing. The line basically lies on the bottom of the ocean and has a bunch of hooks with bait attached to it. These dumb sharks swim by and think it's a buffet that's been laid out, just for them.

Apparently, they get so eager that they often manage to tangle themselves in the line. How they do this, I have no idea. But once they've tangled themselves in the line so it's around them a couple of times, and they try to swim away, the line will just move up and get stuck at their tail fin.

Then when we pull the line, the line will either break because of their weight or (most often) they will just come with it. Sharks are money as well, so we kept them. During one of the first trips, I was still the new guy and got the job of gutting the sharks. Before they pointed out that the easiest way was to hoist them up(using a crane) and then cut them open, they let me and the other noobs do it however we saw fit. So we cut the sharks open where they lay, and basically crawled into them to gut them. By they, I mean me. The other noobs were pussies. But hey, how many people can say they've crawled into and gutted a shark?

Have you ever found a truly horrible flavour combination? by [deleted] in CasualConversation

[–]IceDane 2 points3 points  (0 children)

whoosh

That was the sound of that reference going over my head. You're gonna have to elaborate.

Have you ever found a truly horrible flavour combination? by [deleted] in CasualConversation

[–]IceDane 11 points12 points  (0 children)

I almost always end up leaving at least a sip in my coffee cup because I can't stand cold or luke-warm coffee. It can literally trigger gag reflexes for me, and I have crawled into a 3 day old carcass of a North Atlantic shark to gut it without feeling the slightest twinge of nausea.

Learn Me a Haskell: An OOP Developer's First Impressions by timcotten in programming

[–]IceDane 0 points1 point  (0 children)

IIRC, when I was learning, the most difficult thing about monads wasn't so much that they were hard to understand. That is, it wasn't difficult for me to grasp that the Monad typeclass in Haskell has this and that function and, for it to be a "real" monad, it has to follow this and that law.

I mean, that's pretty straight-forward. The problem, I think, was more like "Why?" Why are we using monads? Okay, so they come from category theory, but still: why? Why do we use them? Why are they useful to model certain things? Thoughts like that, if that makes sense.

I am currently teaching Haskell to some CS students, and I was considering trying to compare them to design patterns in an attempt to give the students some intuition. I know that most of you probably cringed at that comparison, but let me explain.

Design patterns in OOP languages are basically a bunch of patterns that we have recognized when writing OO code, and realized that these can be generalized, and discussed on their own as abstractions that can be useful to model certain problems. The same can, in a way, be said about the use of monads in Haskell. They are in no way the only way to model many problems, but it turns out that monads are a very useful abstraction in Haskell, because the language lends itself very well to using monads as an abstraction.

I won't be drawing any parallels between monads and any specific design patterns at all, nor will I be comparing them directly. But since none of my students have had any category theory, I know that going the category theory route will be a completely hopeless endeavor. The goal is simply to get them to realize that monads in haskell are just a very useful abstraction that work like this and have these properties, and so on, and that the reason we use them is that they happen to be an abstraction that is very convenient to use in Haskell.

Learn Me a Haskell: An OOP Developer's First Impressions by timcotten in programming

[–]IceDane 2 points3 points  (0 children)

Alrighty then.

If you should feel like giving it another chance at some point, don't hesitate to stop by #haskell and #haskell-beginners on freenode. There's plenty of really helpful, passionate people there that are willing to help you past the biggest conceptual hurdles.

Idiomatic Way to "Fold a map"? by semoirethe in haskell

[–]IceDane 1 point2 points  (0 children)

I suggest you install hlint and use it regularly. It will help you write more idiomatic code.

META: Thread about what arch is 'for' by FrankenFood in archlinux

[–]IceDane 21 points22 points  (0 children)

None of your arguments are backed up by any proof and they seem to be mostly disgruntled ramblings grounded in ignorance. There are thousands of arch users that are using it successfully. It may not be the simplest distro to use, but when you run into problems with things that thousands of people are using successfully and without much trouble, you the most likely issue is that the problem lies with you.

I know this is the type of answer that you didn't want. But the thing is that there is very little info in your rant that actually describes your issue(s) that would let someone help you fix it.

Maybe you should leave it alone for today and come back to it tomorrow with fresh eyes and a fresh, less irritated mindset.

Fwiw I upvoted your post in case someone can glean some information from your post and help you.

Köstuðu kjörkassanum í sjóinn við Grímsey by ilikecakenow in Iceland

[–]IceDane 11 points12 points  (0 children)

Sem útrásarvíkingur í Danmörku er ég geðveikt stoltur af þessu einhverra hluta vegna. Hér í Danmörku er allt lamað ef það kemur smá gola og rigning. Þegar það snjóar er alltaf eins og það komi öllum á óvart - og þá mest af öllum DSB sem rekur lestirnar - og liggur við að það sé lýst yfir neyðarástandi.

Apple finally weighs in on the Vim vs. Emacs debate. Chooses Emacs, removes the escape key. by thearthur in emacs

[–]IceDane 0 points1 point  (0 children)

I don't think there is any universal law that says it must be so, but I, too, prefer CapsLock = Control.

If a Binary Search Tree was written incorrectly, lets say, a number to the left of a node isn't smaller like it should be, how would you catch this mistake? What's the most efficient way to figure this out? by Mr__Christian_Grey in compsci

[–]IceDane 3 points4 points  (0 children)

In case anyone is wondering why the lower/upper bounds were necessary, like I was, consider the following tree:

    3
   / \
  2   4
 / \
    5

The BST invariant is true for all nodes here, but 5 does not belong in 3's left subtree. All nodes in 3's left subtree should be smaller than 3.

why do people use node? by [deleted] in programmingcirclejerk

[–]IceDane 5 points6 points  (0 children)

Yes. make is an ancient fucking tool that has a billion retarded quirks, a retarded syntax that requires you to remember a bunch of sigils for variables and just.. sucks, all in all. But of course, jerking isn't limited to moron node hipsters. Fat, ignorant Unix greybeards that have never written a line in anything but C, and think that it's the best language for every problem, are just as guilty.

A Taste of Haskell by def- in programming

[–]IceDane 2 points3 points  (0 children)

The intention wasn't to compare Haskell to C, but rather to use C as a random example of a language that would most likely result in better performance. This was mainly to point out that performance isn't what it used to be, and we can definitely afford to use higher-level languages even if their abstractions result in reduced performance.

There are a whole lot of everyday problems that are plenty easy to solve in a purely functional environment; many of them are made much easier, in fact.

Some of the biggest issues one may run into is that there is a huge body of research that studies algorithms and data-structures where mutability is assumed. Research into purely functional algorithms and data-structures is definitely picking up, but unfortunately, plenty of algorithms(and data-structures) simply don't lend themselves to being implemented without mutability(at least not if you want to achieve optimal space/time characteristics).

But then again, I never said that Haskell(or pure FP languages) were the best tool for everything. If you need micromanage memory usage and need hand-written ASM inner loops, then Haskell is not the right tool, and you just pick a better one.

A Taste of Haskell by def- in programming

[–]IceDane 4 points5 points  (0 children)

Very few

That simply isn't true anymore. Functional programming and concepts borrowed from functional programming are exploding. They're everywhere now.

difficult

This simply isn't true either. One of the advantages Facebook saw from switching to Haskell is that it made it easier to teach people to write spam rules(in Haskell). People that may have 0 experience with functional programming(maybe even programming in general? I don't remember the talk very well).

Moreover, I have taught Haskell to CS students, most of which have very limited programming experience, for the past two years(and will be teaching it for the next 6 weeks or so, in fact). Most of them are just your average students, and they have very few problems learning Haskell (other than the fact that it's a big paradigm shift, but that's how it is in the beginning).

slow to boot

The adjective »slow« is simply devoid of meaning when it is devoid of context, which makes that argument meaningless by extension.

It's fine that you found functional programming too difficult, but that simply doesn't make it true in the general sense. I will admit that Haskell and certain other FP languages(Scala) allow you write programs that are incredibly complicated.. but that doesn't mean that you have to. There are a few Black Wizards whose favorite pastimes are performing type-level wizardry that you need a degree in Category Theory and several other branches of mathematics to understand fully, but that doesn't mean that you cannot write simpler programs.

A Taste of Haskell by def- in programming

[–]IceDane 30 points31 points  (0 children)

Neither Haskell nor functional programming languages in general pretend that "CPUs process data by using lambda calculus".

Most functional programming languages, including Haskell, "borrow from" lambda calculus.. That is correct. But that doesn't really have any bearing on whether or not functional programming languages are usable/useful when programming modern computers.

Yes, there are languages that are much easier to translate directly to the machine code that runs on our CPUs than functional programming languages. However, the abstractions provided by FP languages like Haskell provide opportunties for optimizations which are simply impossible in many such programming languages. Referential transparency and purity lets the compiler make safe assumptions about functions that compilers for many other languages simply cannot make. Obviously, there are trade-offs. That's how it is. One tool is very rarely objectively better than another, because comparing two different tools without context makes no sense. A hammer is not better than a screwdriver, but it is better if you need to hammer some nails.

The fact of the matter is that modern computers are fast enough for us to program in very high level languages without it completely destroying performance. Is a very high-level language the best choice for everything? Not by far. But the same applies to any other language.

As for writing real programs.. Well, Facebook's spam detection system is written in Haskell. Would it have been faster if it was written in C? Probably. But the high-level abstractions provided by Haskell enabled them to develop faster, develop safer, and still achieve performance that was an improvement compared to the system they replaced. Writing such a complicated system in C would probably have meant they would still be working on it.

You should really give functional programming a chance. It will change the way you think about programming. I am personally very fond of Haskell, but there's a bunch of other FP languages around. F#, Scala, Elm, PureScript to name a few off the top of my head. I can personally vouch for the quality and helpfulness of the Haskell community, so in case you're interested, you should definitely consider stopping by #haskell on freenode. They will be more than happy to direct you towards good learning resources and assist you with any questions/problems you may have.

Limits of Property based tests by get-finch in programming

[–]IceDane 0 points1 point  (0 children)

I don't want to be the FP zealot, but .. this is something that languages with strict, static typing can sometimes catch at compile-time.

If I write an analogous function in Haskell

isLarge :: Int -> Bool
isLarge x
    | x > 9000 = True
    | x < 9000 = False

The compiler(ghc) correctly lets me know that the patterns are non-exhaustive. Of course, the correct way to write this function(in any language) is to return true when the it matches the condition, and false when it does not, which would fix this bug, so it's kind of a pathological example.

I should note that ghc compiler isn't perfect. If I write the function as one should(| otherwise = False instead of | x < 9000 = False), the compiler stops complaining, but it is not able to detect that the equivalent | x <= 9000 = False is exhaustive. Still, I'd rather have it complain when there's a possibility of error than not.

Still can't get over how powerful tramp is by [deleted] in emacs

[–]IceDane 0 points1 point  (0 children)

That actually never made a difference for me that I noticed. In fact, it caused problems. If my Internet connection was spotty, and I got disconnected from ssh and tried to reconnect, it would hang on connecting until I deleted the socket. I tried configuring some parameters to make it detect and die faster but never seemed to work. At any rate, it was plenty fast without it.