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
Stringent
Dec 22, 2004


image text goes here

Blinkz0rz posted:

i have a dumb question

my p-lang brain keeps asking what the point of interfaces is if the implementation of any of the interface methods could be wildly different. what's the piece i'm missing?

from my own personal terrible programming background, this is one of the best questions i've seen asked in this thread so kudos.

Adbot
ADBOT LOVES YOU

Blinkz0rz
May 27, 2001

MY CONTEMPT FOR MY OWN EMPLOYEES IS ONLY MATCHED BY MY LOVE FOR TOM BRADY'S SWEATY MAGA BALLS

Shaggar posted:

there are times to use interfaces (most of the time) and there are times to use abstract classes.

so like data structures. a List interface makes way more sense than an abstract List because the underlying storage and plumbing in a list implementation is always going to be wildly different. you might use an array, you might use a linked list, you might use a database table (don't do this) or w/e else. The point is that the List defines how you interact with the underlying data. If someone swaps the list implementation out from under you, it should still be functional even if certain runtime metrics might change (operation performance, memory usage, etc...)

The point is even if you only ever used an ArrayList (and you will only ever mostly use an array list), you still don't care that its an arraylist. you aren't going to be poking at the underlying array. you're still going to be going through all the list interface methods for interaction.

this is the single best explanation for interfaces that i've ever seen. it makes complete sense. thanks shaggar

oh no blimp issue
Feb 23, 2011

guys i am loving lost with haskell
im trying to take a list and get the permutations of that list and ive literally no idea where to start

code:
perm :: [a] -> [[a]]
perm [] = [[]]
perm (x:xs) = I DONT EVEN KNOW
obviously

but trying to think of a way to construct all the different permuted lists is eluding me, like i need to start swapping poo poo around but i can't think of a way to do it

Bloody
Mar 3, 2013

Awia posted:

code:
perm :: [a] -> [[a]]
perm [] = [[]]
perm (x:xs) = [url]http://www.visualstudio.com/[/url]

Shaggar
Apr 26, 2006
often you'll find yourself deep in the weeds when dealing with a problem and it helps to take a step back and re-evaluate it from a wider angle. In this case the first question to ask yourself would be: Why am I using Haskell?

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

Awia posted:

guys i am loving lost with haskell
im trying to take a list and get the permutations of that list and ive literally no idea where to start

code:
perm :: [a] -> [[a]]
perm [] = [[]]
perm (x:xs) = I DONT EVEN KNOW
obviously

but trying to think of a way to construct all the different permuted lists is eluding me, like i need to start swapping poo poo around but i can't think of a way to do it

Use recursion

oh no blimp issue
Feb 23, 2011

Shaggar posted:

often you'll find yourself deep in the weeds when dealing with a problem and it helps to take a step back and re-evaluate it from a wider angle. In this case the first question to ask yourself would be: Why am I using Haskell?

its for a uni module sadly, ive been enjoying it up until this point where its just lost me


using a real language and ide would help yes

Flat Daddy
Dec 3, 2014

by Nyc_Tattoo
ooh isn't there a way to do that by using list as a monad :p

oh no blimp issue
Feb 23, 2011

MALE SHOEGAZE posted:

Use recursion

fukkin genius!

Valeyard
Mar 30, 2012


Grimey Drawer
also see list comprehension

Shaggar
Apr 26, 2006

Flat Daddy posted:

ooh isn't there a way to do that by using list as a monad :p

theres always a way to do it with monads.

gonadic io
Feb 16, 2011

>>=

Awia posted:

guys i am loving lost with haskell
im trying to take a list and get the permutations of that list and ive literally no idea where to start

code:
perm :: [a] -> [[a]]
perm [] = [[]]
perm (x:xs) = I DONT EVEN KNOW
obviously

but trying to think of a way to construct all the different permuted lists is eluding me, like i need to start swapping poo poo around but i can't think of a way to do it

i'm assuming that you're trying to work it out yourself rather than just using a library function (it's in Data.List). male shoegaze is right in that you need to use recusion but also list comprehensions:

it starts:

perm xs = [ x:ys | x <- xs, ys <- ??????? xs]

this way each of the l elements of the list is at the front of a permuted list exactly l times.

oh no blimp issue
Feb 23, 2011

gonadic io posted:

i'm assuming that you're trying to work it out yourself rather than just using a library function (it's in Data.List). male shoegaze is right in that you need to use recusion but also list comprehensions:

it starts:

perm xs = [ x:ys | x <- xs, ys <- ??????? xs]

this way each of the l elements of the list is at the front of a permuted list exactly l times.

yeah, i found the library function ages ago

ok i get ya, thanks for the leg up!

gonadic io
Feb 16, 2011

>>=
also for the people going on about monads:

code:
perm xs = [ x:ys | x <- xs, ys <- ??????? xs]
is the same as, in monadic do-notation that's basically the same as the LINQ,

code:
perm xs = do {
    x <- xs;
    ys <- ??????? xs;
    return (x:ys)}
(with or without the {;}s)

but nobody would bother doing it that way really

gonadic io
Feb 16, 2011

>>=

Flat Daddy posted:

ooh isn't there a way to do that by using list as a monad :p

and you're thinking of powerSets which has a really obtuse 1-liner which i'll go over why it works if people want me to.

powerSets = filterM (const [True, False])

leftist heap
Feb 28, 2013

Fun Shoe

Shinku ABOOKEN posted:

someone mentioned Kotlin in of these threads

is it good? will i end up with a billion auto generated class files a la Scala?

i see its made by jetbrain so maybe its good, but maybe its bad??? anyone tried it here?

i haven't tried it, but how bad could it be in comparison to scala? it's written by the jetbrains people so the ide support is already better. i think i'll be looking for some small tasks to use it for at work to give it a spin.

Shaggar
Apr 26, 2006
Im working on a thing that requires a free text search of fields related to an entity in my database so im using apache solr. the documentation is kind of flaky but after working on if for a while now I have it indexing all the relevant fields, making those fields searchable in free text, and then also making other fields I specify returned for autocomplete suggestion terms. pretty cool, imo.

Jonny 290
May 5, 2005



[ASK] me about OS/2 Warp
that was some interesting gochat, thanks! I'm not changing my mind or anything, we use go at work and i want to get slick with it. we're not writing photoshop or anything we just need insane concurrency and, well, our go daemons run between 40 and 200 times faster than our old ones and are v. needs suiting

Valeyard
Mar 30, 2012


Grimey Drawer
export insane_concurrency=Erlang

Opulent Ceremony
Feb 22, 2012

Shaggar posted:

Im working on a thing that requires a free text search of fields related to an entity in my database so im using apache solr. the documentation is kind of flaky but after working on if for a while now I have it indexing all the relevant fields, making those fields searchable in free text, and then also making other fields I specify returned for autocomplete suggestion terms. pretty cool, imo.

At what point do you decide to do this vs. just make some sprocs to do a LIKE on all the relevant varchars in your database, and if you have too much data maybe have that sproc run on its own slave server that gets replicated to.

Shaggar
Apr 26, 2006
That will work up to a point. eventually you just have too much poo poo and it becomes a pain to manage in procs and also your performance will start to suffer. If you're at the point where you're thinking about dedicating a machine to a stored proc for searching, it makes more sense to use an actual search server. In addition to being more efficient at search you also gain a load of features you just don't get with sql, like autocomplete, spell check, fuzzy matching, synonym matching, etc...

Shaggar
Apr 26, 2006
also if you have messy data that doesn't index well in sql (because your clients are retards who send you bad data) you can clean it up during the solr indexing process. it makes indexing slower, but searches faster and higher quality.

fart simpson
Jul 2, 2005

DEATH TO AMERICA
:xickos:

gonadic io posted:

and you're thinking of powerSets which has a really obtuse 1-liner which i'll go over why it works if people want me to.

powerSets = filterM (const [True, False])

hit me. idgi

gonadic io
Feb 16, 2011

>>=

fart simpson posted:

hit me. idgi

inlining (const [True, False]) into the definition of filterM, then converting it into a list comprehension:

code:
powerSets        :: [a] -> [[a]]
powerSets []     = [[]]
powerSets (x:xs) = [if flag then x:ys else ys
                       | flag <- [True, False]
                       , ys   <- powerSets xs]

gonadic io fucked around with this message at 19:21 on Mar 6, 2015

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

rrrrrrrrrrrt posted:

i haven't tried it, but how bad could it be in comparison to scala? it's written by the jetbrains people

Rofl

leftist heap
Feb 28, 2013

Fun Shoe
ok I tried to desugar this completely

code:
-- ts for filterM
filterM :: (a -> m Bool) -> [a] -> M [a]
filterM _ []     =  return []

-- over list monad
filterM :: (a -> [Bool]) -> [a] -> [[a]]
filterM p (x:xs) =  do
   flg <- p x
   ys  <- filterM p xs
   return (if flg then x:ys else ys)

--desugared
filterM p (x:xs) =
  p x >>=
    \flg -> filterM p xs >>=
      \ys -> return (if flg then x:ys else ys)


--further desugared w/ xs >>= f = concat (map f xs) for list monad
filterM p (x:xs) =
  concat (map
    (\flg ->
      concat (map
        (\ys -> return (if flg then x:ys else ys))
        (filterM p xs)
    (p x))
that took way too long

Shaggar
Apr 26, 2006
that is so awful

leftist heap
Feb 28, 2013

Fun Shoe
the whole exercise just made me think filterM over lists is completely friggin useless in practice.

Solus M.D.
Oct 17, 2007

what did i just post?
i have a dumb question wrt qt

i'm having an issue with an app almost exactly like this

http://stackoverflow.com/questions/17175398/deployed-qt5-application-doesnt-print-or-show-print-dialog

but i'm not having any luck in getting the QT_DEBUG_PLUGIN thing to work. does anyone know how to implement that?

gonadic io
Feb 16, 2011

>>=

Shaggar posted:

that is so awful

oh yeah and what does the byte code for that function in java look like?

rrrrrrrrrrrt posted:

the whole exercise just made me think filterM over lists is completely friggin useless in practice.

agreed i've never ever seen somebody use it except for this

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Doesn't this work?

code:
powerSets :: [a] -> [[a]]
powerSets [] = [[]]
powerSets (x:xs) = map (x:) pSets ++ pSets
    where pSets = (powerSets xs)

leftist heap
Feb 28, 2013

Fun Shoe
no because it doesn't take an hour to understand duh

Shaggar
Apr 26, 2006

HappyHippo posted:

Doesn't this work?

code:
powerSets :: [a] -> [[a]]
powerSets [] = [[]]
powerSets (x:xs) = map (x:) pSets ++ pSets
    where pSets = (powerSets xs)

I have no idea what is going on here

leftist heap
Feb 28, 2013

Fun Shoe
"hmm yes let me just use Haskell to write code that someone without a math phd could understand" - an extremely terrible programmer

gonadic io
Feb 16, 2011

>>=

Shaggar posted:

I have no idea what is going on here

this is the most shaggar post ever lol

"i don't understand this language that i have never written any code and don't know the syntax of"

triple sulk
Sep 17, 2014



Shaggar posted:

I have no idea what is going on here

some sorta tail recursive poo poo or something

Valeyard
Mar 30, 2012


Grimey Drawer

gonadic io posted:

this is the most shaggar post ever lol

"i don't understand this language that i have never written any code and don't know the syntax of"

lol

Shaggar
Apr 26, 2006

gonadic io posted:

this is the most shaggar post ever lol

"i don't understand this language that i have never written any code and don't know the syntax of"

in most languages you can tell what they do cause the syntax is reasonable. Haskells syntax is awful on every level and is completely indefensible

leftist heap
Feb 28, 2013

Fun Shoe
no in most languages you spell out everything in retarded baby steps that joe blow idiot can follow because he can't understand anything even remotely declarative.

Adbot
ADBOT LOVES YOU

MononcQc
May 29, 2007

Shaggar posted:

I have no idea what is going on here

Recursively defines a powerset as the first element of the list added to all powersets of the remainder of the list.

so in [1,2,3] it is defined as:


: 1 added to all powersets of [2,3]
-> 2 added to all powersets of [3]
        -> powersets of [3] are [3] and []
     -> 2 added to [] and [3], yielding [], [2], [3] and [2,3]
   -> 1 added to [], [3], [2,3], [2]
-> [], [1], [2], [3], [2,3], [1,2], [1,3], [1,2,3]

code:
powerSets :: [a] -> [[a]]                  <--- takes a list and returns a list of lists of similar terms
powerSets [] = [[]]                        <--- an empty list ([]) has the set of sets [[]] (only [] is in it)
powerSets (x:xs) = map (x:) pSets ++ pSets <--- the head of the list is x, the rest is xs, and you apply
    where pSets = (powerSets xs)                x to the head of each of the powersets of the rest of the list
                                                then add the existing powersets at the end

MononcQc fucked around with this message at 21:01 on Mar 6, 2015

  • Locked thread