Code Monkey home page Code Monkey logo

Comments (11)

Bodigrim avatar Bodigrim commented on July 17, 2024

Or even go for

data SCC vertex = SCC vertex [vertex]

and AcyclicSCC / CyclicSCC become pattern synonyms for backward compatibility.

from containers.

treeowl avatar treeowl commented on July 17, 2024

Yes, let's do something of this sort. Your second representation doesn't seem to distinguish properly between vertices with no edges and ones with a single edge to themselves.

import Data.Graph

main :: IO ()
main =  do
  print $ stronglyConnComp [((), (), [()])]
  print $ stronglyConnComp [((), (), [])]

This gives

[CyclicSCC [()]]
[AcyclicSCC ()]

As I understand it, your SCC would represent these two the same.

from containers.

Bodigrim avatar Bodigrim commented on July 17, 2024

Your second representation doesn't seem to distinguish properly between vertices with no edges and ones with a single edge to themselves.

Ah, excellent point.

How about this? Any better naming than CyclicSCC'?

data SCC vertex = AcyclicSCC vertex
                | CyclicSCC' (NonEmpty vertex)

pattern CyclicSCC :: [vertex] -> SCC vertex
pattern CyclicSCC xs <- CyclicSCC' (NE.toList -> xs) where
  CyclicSCC xs = CyclicSCC' (NE.fromList xs)

{-# COMPLETE AcyclicSCC, CyclicSCC #-}

from containers.

treeowl avatar treeowl commented on July 17, 2024

I must admit to some trepidation about committing to NonEmpty given the current lack of a plan for improving its laziness story. If we do use it, I imagine it should be strict and unpacked.

from containers.

Bodigrim avatar Bodigrim commented on July 17, 2024

Do you mean CyclicSCC' !vertex ![vertex]?

from containers.

treeowl avatar treeowl commented on July 17, 2024

I meant if you want NonEmpty it should probably be {-# UNPACK #-} !(NonEmpty vertex). But unpacking by hand wouldn't be unreasonable either.

from containers.

Bodigrim avatar Bodigrim commented on July 17, 2024

{-# UNPACK #-} and a bang are more readable, I'd rather keep NonEmpty. Shall I prepare a PR? @meooow25 any comments?

from containers.

treeowl avatar treeowl commented on July 17, 2024

I'd like to see how this affects the code, yeah.

from containers.

meooow25 avatar meooow25 commented on July 17, 2024

Can we maybe skip introducing the partial CyclicSCC -> CyclicSCC' pattern? It's unlikely someone would be making their own SCCs. And even with the pattern it's a breaking change if they do CyclicSCC [].

from containers.

treeowl avatar treeowl commented on July 17, 2024

@meooow25 , we can just make it unidirectional, right?

from containers.

meooow25 avatar meooow25 commented on July 17, 2024

Yes, that's what I meant, should have stated explicitly.
Also this is only a suggestion, it comes down to whether we really don't want to break some code out there that is constructing CyclicSCCs and always with non-empty lists.

from containers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.