/dpt/ - Daily Programming Thread

Haskell edition
What are you working on, Jow Forums?

Previous thread:

Attached: 0.png (1000x1300, 786K)

Other urls found in this thread:

github.com/arnaucode/coffeeMiner
en.wikipedia.org/wiki/Modulo_operation
content.riscv.org/wp-content/uploads/2018/05/slidesThomasBourgeat.pdf
github.com/ericniebler/range-v3
twitter.com/NSFWRedditImage

haskell!

why is everyone talking about haskell just as i decided to learn it? is haskell a meme now?

confirmation bias

hello we will be your haskell senpais for today

Attached: anim haskell.jpg (480x480, 56K)

Everyone was talking about Haskell already user. It's not necessarily a meme but it is not actually being used anywhere, but still fun to learn and program in.

thank you for posting a programming (anime) related image OP.

Haskell is the established hobbyist lang, that's finally gotten niche production use in the real world.

package main

import (
"fmt"
"net"
)

func GetNet() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "Error!"
}
for _, address := range addrs {
// check the address type and if it is not a loopback the display it
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.String()
}
}
}
return "Error!"
}

func main() {
fmt.Println(GetNet())
}


Can i get some feedback? How would you do it differently.

whats the best first language to learn?

Attached: 1446307271627.png (374x347, 171K)

does C# have something similar as
stack hoogle / stack haddock ?

Those tools are amazing,I would save hours by avoiding to use that super-bloated disgusting piece of shit called msdn.

Haskell

Why do I love anime girls with programming books so much?

maybe python?

why do you want to learn to program?

rust, C++, Idris, crystal, nim, forth

because you like to imagine meeting a cute girl who could talk to you about programming

Because It's the best.

>How would you do it differently.
By not using go

I'm trying to learn go tho

don't do stringly typed programming, return something like an optional or either type

Thanks. I'm in the process of rewriting/improving this:
github.com/arnaucode/coffeeMiner

It will be my first Go project.

how new are you fag

have you even reached satori?

>Actually caring about whether something is a string or another type

Types are an illusion. At the end of it all, all programs are just data operating on data, strings upon strings. Open your mind's eye to the eval/apply duality.

Attached: Eyes5.jpg (700x525, 222K)

haskell, your brain isn't tainted by the C disease

you already know maths from high school, so haskell is basically that

Attached: DcSZGc_WsAEVyOD.jpg (800x450, 35K)

im oldfag actually, been professionally programming for 10 years. i work in a wonderful """""""""enterprise""""""""" environment, please kill me, then give me a haskell job

why is -1 % 2 giving me -1 in C?

its a small meme
not really used much in industry but a decent amount of hobbyist stuff and open source projects use it

damn, I work in java and javascript and it sucks

I can't curry anything properly, can't partial application properly, we get null pointers, checked exceptions, fucking mappers lmao

Instead of returning the string "Error!", return the actual error: I guess the idiomatic go way is to have the function return a string and an error, and call it with net, err := GetNet()]/code]
Anyway, this allows the caller of the function to actually see what the error was and handle it properly

Attached: errnil.jpg (700x720, 82K)

I don't get this anymore but sometime around year 5 or 6 I would dream about checking for null.

en.wikipedia.org/wiki/Modulo_operation
look at the table

god dam, thanks. never knew about this.

Is any functional programming language that has real life usage? don't meme me with haskell.

Java

Facebook uses haskell to filter spam, and I've heard F# is used in the finance world.

haskell, F# have real world usage by the financial sector

and clojure i guess, but why would you want to program in a dynamically typed lang anyway

Jane Street uses OCaml.

Haskell

first learn haskell

>C# uses PascalCase for methods as well as types, so poor allocation of the namespace there
no it's not. there's no reason for type and method names to use different conventions, because they're semantically distinct/unambiguous, and both are type-level metadata. when using PascalCase for both, the only method name that becomes unavailable at class scope is the class name itself, which works out because that's already specialized for the constructor anyway (and otherwise type/method name collision is not a problem because C# has no free/namespace-scope functions). it allows camelCase to be reserved for locals, method parameters, and fields (ease/immediacy of distinction between local/nonlocal or private/public symbols (or even effectively between interface and implementation) is far more important than that between type and method names, which doesn't tend to be a source of ambiguity anyway). one notable benefit is that it allows a public property and its underlying private field to have the same name, differing only in convention, clearly and immediately indicating their relationship (interface vs. implementation) in a standard/predictable way, without requiring the use of some arbitrary prefix or suffix

You are the meme. Stop spacing a like a turd with light and dark bands.

The Scheme programming language.

Couldn't have said it better (maybe shorter)

People have been doublespacing on Jow Forums long before reddit was popular. Reddit spacing is a stupid tribalistic meme

Reddit or not. It is still retarded and annoying

what do you do when you fall in love with a github profile ?

harass through pull requests.

>functional programming language
>java
pic related
Also, what ever happened to scala? Nobody is suggesting it.

Attached: onmqPFu.gif (1280x720, 489K)

scala is a fucking mess that's why

What's the fastest way to merge 2 maps in java?
The maps can have the same keys, but they can also have different keys.
The mapping is .
This merging of maps is the main bottleneck in my algorithm, so the faster the better

>retarded and annoying
Just like you.

You want overlapping keys to result in a list of each value from each map?

I wrote an X11 version of Hello World.
// Hello World program in the X11 environment
// Command line options to gcc:
// -lX11 -L/opt/X11/lib -I/opt/X11/include

#include
#include
#include

#include
#include

int main( int argc, char **argv ){

// Setup:
Display *dpy = XOpenDisplay( NULL );
int scr = DefaultScreen( dpy );
Window win = XCreateSimpleWindow( dpy, RootWindow( dpy, scr ), 0, 0, 200, 75, 1, BlackPixel( dpy, scr ), WhitePixel( dpy, scr ) );
XSelectInput( dpy, win, ExposureMask );

// Output:
XMapWindow( dpy, win );
XEvent e;
while( true ){
XNextEvent( dpy, &e );
if( e.type == Expose ){
const char *s = "Hello, World!";
XDrawString( dpy, win, DefaultGC( dpy, scr ), 20, 20, s, strlen( s ) );
}
if( e.type == ClientMessage ) break;
}

// Cleanup:
XDestroyWindow( dpy, win );
XCloseDisplay( dpy );

return 0;
}

It was difficult figuring out what all the functions do, but I've finally got the hang of it now.

Avoid flatmap and map(generally streams).
A simple loop and checking if item exists should be enough.

Ruby is functional and has real world applications. But if you mean pure functional languages, I don't know of any.

No need to get upset. But hey! At least you stopped spacing like a retard.

The maps already exist out of lists mapped to keys.
All keys need to be retained, but when there's a duplicate key the corresponding lists need to be merged,

That's how I've been doing it so far, just wondered if there was anything faster.

Isn't there addAll()? I think it overwrites keys or was it putAll()? Ffffs. Something like that.

You're the one sperging.

This makes long text a lot more readerable, and doesn't look like a coalesced mess of text like this

Now write a hello wayland version!

There's computeIfAbsent, which creates the list if it doesnt exist and then addalls the list value from the map to copy.
There's putall, but it replaces all keys, so the lists don't get merged

But I think I found something that removes the need of merging the maps all together

Thanks for thinking with me anons

>Ruby is functional
good joke

content.riscv.org/wp-content/uploads/2018/05/slidesThomasBourgeat.pdf

Some real world usage Haskell.

Gentoo

ocaml, haskell, f#

Thanks pajeet

I'm bad at programming and I'm a talentless hack. How hard would it be to make a 3D mech simulation game that uses a flight stick, a VR headset, pedals, and a control keypad?

That's spacing like retard. Have you never taken an english class? A lack of education isn't something you take out on others.

Mecha game
Use unreal engine.

package main

import (
"fmt"
"net"

"github.com/pkg/errors"
)

func GetNet() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", errors.Wrap(err, "error getting addresses")
}
for _, address := range addrs {
// check the address type and if it is not a loopback the display it
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.String(), nil
}
}
}
return "", errors.Wrap(err, "error doing something else")
}

func main() {
res, err := GetNet()
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(res)
}
}

It has lambdas, higher order functions, functions treated as data, immutable numeric variables. How is that not functional?

If you consider Scala an FPL, then I've seen a decent amount of companies using it.

Literrally worse than java

ok Jow Forums give me the best online resources to learn haskell and ill give it a go

hi brainlet here
im trying to build a list a of ip:port combinations with python but too dumb to figure out how to determine if something is a valid ip:port combination. regex sucks for this. i am scraping a website and the source has text other than ip address + port.

google.com

use the merge function
map.merge(key, newList, (l1, l2) -> {
l1.addAll(l2);
return l1;
});

>look at me i'm so smart because i write recursive functions instead of loops
>iterationplebs don't know what it's like to spend time implementing memoization to try to lessen the performance impact of my inherently flawed recursive algorithm
>recursive algorithms are more ""beautiful"" than the equivalent iterative solution. you don't see it? lol you're the brainlet

Attached: recursionfag.png (645x729, 90K)

you are confusing function with procedure. a functional programming language is based on lambda caculus, is declarative (no statements), has notion of currying and partial application. for example, in ocaml, you are really defining functions.

If your programming language doesn't perform tail call optimization it's a shit lang

I think it's better than java and looks good but we all have our lives to live

There's no fucking way you think iterative methods are more efficient. I probably just fell for the bait though.

Attached: furdervaterland.jpg (440x460, 22K)

t. retarded recursionfags

t. brainlet who rage quit FP

at least you know it's a FP thing. keep that shit away from C++

What is your definition of "valid"? Ip addresses range from 0-255 on 4 octets and ports range from 0-65535.

Have fun struggling with a shitty stack implementation faggot while I save time and effort by writing a flawless nlogn algorithm.

>>recursive algorithms are more ""beautiful"" than the equivalent iterative solution.
but both are iterative... do you even have the least of knowledge of what you are talking about?

recursive in this context means using recursive function calls as opposed to loops

>header only library

Attached: 1504295972933.png (444x357, 165K)

Thanks user. This certainly helped me out. I'm gonna get it to take the CIDR and get all possible addresses. Then ping each host for discovery.

99% of the time you should be using arrays and not worry at all about using stacks or recursive functions

>copyleft library

Attached: 1472007964659.png (640x360, 230K)

why iptables doesn't has an option to add rule only if it doesn't exist?
I can not use bash
anyone knows a simple one liner to do this, using command chain operators(&& || ;)

but tail recursion is iteration, it's literally explained in the first chapter of SICP. you are confusing declarative with imperative; loops are based on statements (turing marchine) while recursion is functional (lambda calculus). this is really embarrassing.

s-sorry

using tail recursion in languages like C or C++ is what's really embarrassing

>she doesn't program with lazy ranges in sepples
github.com/ericniebler/range-v3