Esempio n. 1
0
maybe<std::size_t> find_first_instance_of_token
        (const Container& token, const Container& xs)
{
    if (size_of_cont(token) > size_of_cont(xs))
        return nothing<std::size_t>();

    auto itInBegin = std::begin(xs);
    auto itInEnd = itInBegin;
    internal::advance_iterator(itInEnd, size_of_cont(token));
    std::size_t idx = 0;
    std::size_t last_possible_idx = size_of_cont(xs) - size_of_cont(token);
    while (idx != last_possible_idx)
    {
        if (std::equal(itInBegin, itInEnd, std::begin(token)))
        {
            return just(idx);
        }
        ++itInBegin;
        ++itInEnd;
        ++idx;
    }
    if (std::equal(itInBegin, itInEnd, std::begin(token)))
    {
        return just(idx);
    }
    return nothing<std::size_t>();
}
Esempio n. 2
0
File: main.cpp Progetto: CCJY/coliru
int main() {
    maybe<int> q(1);
    maybe<int> x;
    maybe<get_fucked> death( 1 ); // boom
    maybe<get_fucked> deathagain; // have fun~

    std::cout << std::boolalpha;
    std::cout << (q != nothing) << ' ' << (nothing != q) << ' ';
    std::cout << (x != q) << ' ' << (q != x) << ' ' << (q == q);
    std::cout << ' ' << (q == just(1)) << ' ' << (just(1) == q);
    std::cout << ' ' << (x == x) << ' ' << (x == nothing) << ' ';
    std::cout << ' ' << (nothing == x);
}
Esempio n. 3
0
static BOOL next(int ch)
{ /* get next digit - returns FALSE if there is a problem  */
    int cv;
    result=FALSE;
    if (ipt>=dlen) return FALSE;
    if (ch=='/' || ch=='.')
    {
        if (delim || (ch=='/' && ipt==0)) return FALSE;
        delim=TRUE;
    }
    else
    {
        if (ch>='A' && ch<='F') cv=10+(ch-'A');
        else                    cv=ch-'0';
        if (mip->IOBASE<=cv) return FALSE;
    }
    if (ipt==0 && ch=='0') clr();
    else
    {
        mybuff[ipt++]=ch;
        mybuff[ipt]='\0';
    }
    just(mybuff);
    cinstr(x,mybuff);
    newx=TRUE;
    return TRUE;
}
Esempio n. 4
0
//TSP -> NN -> Generations( g, ForkJoin ( n, GA -> 2-OPT ) ) -> TSP'
void Pipeline2(tsp_class& tsp_instance, unsigned int number_of_tasks, 
			                            unsigned int number_of_generations)
{
	#pragma region "PipelineConfiguration"
	auto a = Args<General_args_type>(make_General_args(number_of_generations, number_of_tasks));
	auto sa = Args<SA_args_type>();
	auto aco = Args<ACO_args_type>();
	auto ga = Args<GA_args_type>(make_GA_args(1000, 10, 5, 50000, 10, 0.9));

	const char* pipeline_description = "TSP -> NN -> Generations( g, ForkJoin ( n, GA -> 2-OPT ) ) -> TSP'";
	display_args(pipeline_description, a, sa, aco, ga);
	
	auto g = a[0].number_of_iterations_or_generations;
	auto n = a[0].number_of_tasks_in_parallel;
	auto _TSP = TSP(just(tsp_instance));
	auto _DisplayInput = Display("TSP INPUT", DisplayFlags::All);
	auto _NN = Measure(NN(), Display("NEAREST NEIGHBOUR", DisplayFlags::EmitMathematicaGraphPlot));	
	auto _GA_2OPT = Chain(GA(ga[0].population_size, ga[0].mutation_percentage, ga[0].group_size, 
							 ga[0].number_of_generations, ga[0].nearby_cities, ga[0].nearby_cities_percentage), _2OPT());
	auto _ForkJoin = [](unsigned int n, TSP::transformer_type map_fun){ return Measure(ForkJoin(n, map_fun)); };
	auto _DisplayOutput = Display("TSP OUTPUT", DisplayFlags::EmitMathematicaGraphPlot); 
	#pragma endregion

	//TSP -> NN -> Generations( g, ForkJoin ( n, GA -> 2-OPT ) ) -> TSP'
	auto result = _TSP
					.map(_DisplayInput)
					.map(_NN)
					.map(Generations(g, _ForkJoin(n, _GA_2OPT)))
					.map(_DisplayOutput);
}
Esempio n. 5
0
//TSP -> NN -> Generations( g, ForkJoin ( n, SA -> 2-OPT ) ) -> TSP'
void Pipeline1(tsp_class& tsp_instance, unsigned int number_of_tasks, unsigned int number_of_generations)
{
	#pragma region "PipelineConfiguration"
	auto a = Args<General_args_type>(make_General_args(number_of_generations, number_of_tasks));
	auto sa = Args<SA_args_type>(make_SA_args(1000.0, 0.00001, 0.999, 400));
	auto aco = Args<ACO_args_type>();
	auto ga = Args<GA_args_type>();

	const char* pipeline_description = "TSP -> NN -> Generations( g, ForkJoin ( n, SA -> 2-OPT ) ) -> TSP'";
	display_args(pipeline_description, a, sa, aco, ga);
	
	auto g = a[0].number_of_iterations_or_generations;
	auto n = a[0].number_of_tasks_in_parallel;
	auto _TSP = TSP(just(tsp_instance));
	auto _DisplayInput = Display("TSP INPUT", DisplayFlags::All);
	auto _NN = Measure(NN(), Display("NEAREST NEIGHBOUR", DisplayFlags::EmitMathematicaGraphPlot));	
	auto _SA_2OPT = Chain(SA(sa[0].initial_temperature, sa[0].stopping_criteria_temperature, 
							 sa[0].decreasing_factor, sa[0].monte_carlo_steps), _2OPT());
	auto _ForkJoin = [](unsigned int n, TSP::transformer_type map_fun){ return Measure(ForkJoin(n, map_fun)); };
	auto _DisplayOutput = Display("TSP OUTPUT", DisplayFlags::EmitMathematicaGraphPlot); 
	#pragma endregion

	//TSP -> NN -> Generations( g, ForkJoin ( n, SA -> 2-OPT ) ) -> TSP'
	auto result = _TSP
					.map(_DisplayInput)
					.map(_NN)
					.map(Generations(g, _ForkJoin(n, _SA_2OPT)))
					.map(_DisplayOutput);
}
Esempio n. 6
0
monad_t* maybe_return(void* v)
{
    if(v)
        return just(v);
    else
        return nothing();
}
Esempio n. 7
0
static void drawit(void)
{ /* Draw calculator */
    int i,j;
    char line[40],tline[40],bline[40];
    cset(1);
    line[0]=DTLHC;
    for (i=1;i<38;i++) line[i]=DHORZ;
    line[38]=DTRHC;
    line[39]='\0';
    aprint(ORDINARY,1,1,line);
    for (i=1;i<22;i++) apchar(ORDINARY,1,1+i,DVERT); 
    line[0]=DBLHC;
    line[38]=DBRHC;
    aprint(ORDINARY,1,23,line);
    for (i=1;i<22;i++) apchar(ORDINARY,39,1+i,DVERT);
    line[0]=LSIDE;  /* draw in the bar */
    for (i=1;i<38;i++) line[i]=HORZ;
    line[38]=RSIDE;
    aprint(ORDINARY,1,4,line);
    line[0]=tline[0]=bline[0]=SPACE;
    line[36]=tline[36]=bline[36]=SPACE;
    line[37]=tline[37]=bline[37]='\0';
    for (i=1;i<36;i++)
    {
        switch (i%5)
        {
        case 1 : tline[i]=TLHC;
                 bline[i]=BLHC;
                 line[i]=VERT;
                 break;
        default: tline[i]=HORZ;
                 bline[i]=HORZ;
                 line[i]=SPACE;
                 break;
        case 0 : tline[i]=TRHC;
                 bline[i]=BRHC;
                 line[i]=VERT;
                 break;
        }
    } 
    for (j=0;j<6;j++)
    {
        aprint(ORDINARY,2,5+3*j,tline);
        aprint(ORDINARY,2,6+3*j,line);
        aprint(ORDINARY,2,7+3*j,bline);
    }
    cset(0);
    for (j=0;j<6;j++)
        for (i=0;i<7;i++)
            aprint(ORDINARY,4+5*i,6+3*j,keys[j][i]);
    aprint(HELPCOL,2,24,"Type 'H' for help on/off, 'O' to exit");
    cotstr(x,mip->IOBUFF);
    just((char *)mip->IOBUFF);
    getstat();
    show(TRUE);
}
Esempio n. 8
0
File: window.cpp Progetto: maseek/HP
	Maybe<Window> open_IO( Engine& engine, const WindowConfig& windowConfig )
	{
		std::wstring windowNameW = s2ws( "HP_FP::" + engine.name );
		Window window{ nullptr, windowNameW.c_str( ) };
		if ( isOnlyInstance_IO( window.name ) )
		{
			// window class details
			WNDCLASSEX windowClass = { 0 };
			windowClass.cbSize = sizeof( WNDCLASSEX );
			windowClass.style = CS_VREDRAW | CS_HREDRAW;
			windowClass.lpfnWndProc = &windowProc_IO;
			windowClass.cbClsExtra = 0;
			windowClass.cbWndExtra = 0;
			windowClass.hInstance = GetModuleHandle( nullptr );
			windowClass.hIcon = 0;
			windowClass.hIconSm = 0;
			windowClass.hCursor = 0;
			windowClass.hbrBackground = 0;
			windowClass.lpszMenuName = 0;
			windowClass.lpszClassName = window.name;
			// register the window
			if ( RegisterClassEx( &windowClass ) )
			{
				// find position and size
				HDC screenDC = GetDC( nullptr );
				unsigned left = ( GetDeviceCaps( screenDC, HORZRES ) - windowConfig.width ) / 2;
				unsigned top = ( GetDeviceCaps( screenDC, VERTRES ) - windowConfig.height ) / 2;
				unsigned width = windowConfig.width;
				unsigned height = windowConfig.height;
				ReleaseDC( nullptr, screenDC );
				// set the style of the window
				DWORD style = WS_VISIBLE;
				if ( windowConfig.windowStyle == WindowStyle::Window )
				{
					style |= WS_CAPTION | WS_MINIMIZEBOX | WS_THICKFRAME | WS_MAXIMIZEBOX | WS_SYSMENU;
					// adjust the window size with the borders etc.
					RECT rectangle = { 0, 0, windowConfig.width, windowConfig.height };
					AdjustWindowRect( &rectangle, style, false );
					width = rectangle.right - rectangle.left;
					height = rectangle.bottom - rectangle.top;
				}
				// create the window
				window.handle = CreateWindowEx( 0, window.name, window.name, style, left, top, width, height, GetDesktopWindow( ), nullptr, GetModuleHandle( nullptr ), &engine );
				if ( window.handle == nullptr )
				{
					ERR( GetLastError( ) );
					return nothing<Window>( );
				}
				if ( windowConfig.windowStyle == WindowStyle::Fullscreen )
				{
					switchToFullscreen_IO( window.handle, windowConfig );
				}
			}
		}
		return just( std::move( window ) );
	}
Esempio n. 9
0
monad_t* increment_odds(int* val)
{
    if(!val || 0 == ((*val) % 2))
    {
        return nothing();
    }
    int* v = malloc(sizeof(int));
    *v = (*val) + 1;
    return just(v);
}
Esempio n. 10
0
int main()
{
    int x = 2;
    int y = 4;
    int z = 6;
    monad_t* m = just(&x);
    print_maybe_int_monad(m);
    m = m->mbind(m, (bound_func)increment_evens);
    print_maybe_int_monad(m);
    m = m->mbind(m, (bound_func)increment_evens);
    print_maybe_int_monad(m);
    m = just(&y);
    m = m->mbind(m, (bound_func)increment_evens);
    m = m->mbind(m, (bound_func)increment_odds);
    print_maybe_int_monad(m);
    m = just(&z);
    m = m->mbind(m, (bound_func)increment_odds);
    print_maybe_int_monad(m);

    return 0;
}
Esempio n. 11
0
monad_t* increment_evens(int* val)
{
    if(!val) {
        return nothing();
    }
    if(0 != ((*val) % 2))
    {
        return nothing();
    }
    int* v2 = malloc(sizeof(int));
    *v2 = (*val) + 1;
    return just(v2);
}
Esempio n. 12
0
maybe<TOut> first_match_by(F f, const ContainerIn1& xs, const ContainerIn2& ys)
{
    const auto maybe_idx = first_match_idx_by(f, xs, ys);
    if (is_nothing(maybe_idx))
    {
        return nothing<TOut>();
    }
    else
    {
        const auto idx = maybe_idx.unsafe_get_just();
        return just(std::make_pair(
            elem_at_idx(idx, xs),
            elem_at_idx(idx, ys)));
    }
}
Esempio n. 13
0
maybe<std::size_t> first_match_idx_by(F f,
    const ContainerIn1& xs, const ContainerIn2& ys)
{
    auto itXs = std::begin(xs);
    auto itYs = std::begin(ys);
    std::size_t minSize = std::min(size_of_cont(xs), size_of_cont(ys));
    for (std::size_t i = 0; i < minSize; ++i)
    {
        if (internal::invoke(f, *itXs, *itYs))
        {
            return just(i);
        }
        ++itXs;
        ++itYs;
    }
    return nothing<std::size_t>();
}
Esempio n. 14
0
//TSP -> NN -> Generations( g, ForkJoin ( n, ACO -> 2-OPT ) ) -> TSP'
void Pipeline3(tsp_class& tsp_instance, unsigned int number_of_tasks, 
			                            unsigned int number_of_generations)
{
	#pragma region "PipelineConfiguration"
	auto a = Args<General_args_type>(make_General_args(number_of_generations, number_of_tasks));
	auto sa = Args<SA_args_type>();
	auto ga = Args<GA_args_type>();

	const int aco_iterations = static_cast<int>(tsp_instance.cities.size() * 100);
	const ants_type::size_type number_of_ants = tsp_instance.cities.size();
	const double BASE_PHEROMONE = 1.0f / static_cast<double>(tsp_instance.cities.size());
	const double ALPHA = 1.0;
	const double BETA  = 1.0;
	const double RHO   = 0.9;
	const double QVAL  = 70;
	auto aco = Args<ACO_args_type>(make_ACO_args(aco_iterations, number_of_ants, 
								   BASE_PHEROMONE, ALPHA, BETA, RHO, QVAL));	

	const char* pipeline_description = "TSP -> NN -> Generations( g, ForkJoin ( n, ACO -> 2-OPT ) ) -> TSP'";
	display_args(pipeline_description, a, sa, aco, ga);
	
	auto g = a[0].number_of_iterations_or_generations;
	auto n = a[0].number_of_tasks_in_parallel;
	auto _TSP = TSP(just(tsp_instance));
	auto _DisplayInput = Display("TSP INPUT", DisplayFlags::All);
	auto _NN = Measure(NN(), Display("NEAREST NEIGHBOUR", DisplayFlags::EmitMathematicaGraphPlot));	
	auto _ACO_2OPT = Chain(ACO(aco[0].aco_iterations, aco[0].number_of_ants, aco[0].base_pheromone, 
								aco[0].favor_pheromone_level_over_distance, 
								aco[0].favor_distance_over_pheromone_level, 
								aco[0].value_for_intensification_and_evaporation, 
								aco[0].pheronome_distribution), _2OPT());
	auto _ForkJoin = [](unsigned int n, TSP::transformer_type map_fun){ return Measure(ForkJoin(n, map_fun)); };
	auto _DisplayOutput = Display("TSP OUTPUT", DisplayFlags::EmitMathematicaGraphPlot); 
	#pragma endregion

	//TSP -> NN -> Generations( g, ForkJoin ( n, ACO -> 2-OPT ) ) -> TSP'
	auto result = _TSP
					.map(_DisplayInput)
					.map(_NN)
					.map(Generations(g, _ForkJoin(n, _ACO_2OPT)))
					.map(_DisplayOutput);
}
Esempio n. 15
0
static BOOL act(int p,int q)
{ /* act on selected key */
    int k,n,c;
    aprint(PRESSED,4+5*p,6+3*q,keys[q][p]);
    switch(p+7*q)
    {
    case 0:  if (degrees) fmul(x,radeg,x);
             if (hyp) fsinh(x,x);
             else     fsin(x,x);
             newx=TRUE;
             break;
    case 1:  if (degrees) fmul(x,radeg,x);
             if (hyp) fcosh(x,x);
             else     fcos(x,x);
             newx=TRUE;
             break;
    case 2:  if (degrees) fmul(x,radeg,x);
             if (hyp) ftanh(x,x);
             else     ftan(x,x);
             newx=TRUE;
             break;
    case 3:  if (lgbase>0)
             {
                 n=size(x);
                 if (abs(n)<MR_TOOBIG)
                 {
                     convert(lgbase,x);
                     if (n<0) frecip(x,x);
                     fpower(x,abs(n),x);
                     newx=TRUE;
                     break;
                 }
                 if (lgbase==2)  fmul(x,loge2,x);
                 if (lgbase==10) fmul(x,loge10,x);
             }
             fexp(x,x);
             newx=TRUE;
             break;
    case 4:  mip->RPOINT=!mip->RPOINT;
             newx=TRUE;
             break;
    case 5:  clrall();
             newx=TRUE;
             break;
    case 6:  return TRUE;
    case 7:  if (hyp) fasinh(x,x);
             else     fasin(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 8:  if (hyp) facosh(x,x);
             else     facos(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 9:  if (hyp) fatanh(x,x);
             else     fatan(x,x);
             if (degrees) fdiv(x,radeg,x);
             newx=TRUE;
             break;
    case 10: flog(x,x);
             if (lgbase==2)  fdiv(x,loge2,x);
             if (lgbase==10) fdiv(x,loge10,x);
             newx=TRUE;
             break;
    case 11: newx=TRUE;
             k=3;
             forever
             {
                 aprint(INVER,2+stptr[k],2,settings[k][option[k]]);
                 curser(2+stptr[k],2);
                 c=arrow(gethit());
                 if (c==1)
                 {
                     if (option[k]==nops[k]) option[k]=0;
                     else option[k]+=1;
                     continue;
                 }
                 aprint(STATCOL,2+stptr[k],2,settings[k][option[k]]);
                 if (c==0 || c==2) break;
                 if (c==4 && k>0) k--;
                 if (c==3 && k<3) k++;
             }
             setopts();
             break;
    case 12: chekit(7);
             break;
    case 13: result=FALSE;
             if (ipt==0) break;
             ipt--;
             mybuff[ipt]='\0';
             if (ipt==0) clr();
             just(mybuff);
             cinstr(x,mybuff);
             newx=TRUE;
             break;
    case 14: if (!next('7')) putchar(BELL);
             break;
    case 15: if (!next('8')) putchar(BELL);
             break;
    case 16: if (!next('9')) putchar(BELL);
             break;
    case 17: chekit(6);
             break;
    case 18: chekit(5);
             break;
    case 19: chekit(4);
             break;
    case 20: copy(m,x);
             newx=TRUE;
             break;
    case 21: if (!next('4')) putchar(BELL);
             break;
    case 22: if (!next('5')) putchar(BELL);
             break;
    case 23: if (!next('6')) putchar(BELL);
             break;
    case 24: fmul(x,x,x);
             newx=TRUE;
             break;
    case 25: froot(x,2,x);
             newx=TRUE;
             break;
    case 26: chekit(3);
             break;
    case 27: brkt=0;
             chekit(0);
             flag=OFF;
             fadd(m,x,m);
             newx=TRUE;
             break;
    case 28: if (!next('1')) putchar(BELL);
             break;
    case 29: if (!next('2')) putchar(BELL);
             break;
    case 30: if (!next('3')) putchar(BELL);
             break;
    case 31: frecip(x,x);
             newx=TRUE;
             break;
    case 32: fpi(x);
             newx=TRUE;
             break;
    case 33: chekit(2);
             break;
    case 34: negify(x,x);
             newx=TRUE;
             break;
    case 35: if (!next('0')) putchar(BELL);
             break;
    case 36: if (!next('/')) putchar(BELL);
             break;
    case 37: if (!next('.')) putchar(BELL);
             break;
    case 38: if (ipt>0)
             {
                 putchar(BELL);
                 result=FALSE;
             }
             else
             {
                 zero(x);
                 brkt+=1;
                 newx=TRUE;
             }
             break;
    case 39: if (brkt>0)
             {
                 chekit(0);
                 brkt-=1;
             }
             else
             {
                 putchar(BELL);
                 result=FALSE;
             }
             break;
    case 40: chekit(1);
             break;
    case 41: brkt=0;
             equals(0);
             flag=OFF;
             break;
    }
    return FALSE;
}
Esempio n. 16
0
void Maybe_m_return(OPObject* _self, void* data)
{
  Maybe* self = (Maybe*) _self;
  just(self, data);
}
Esempio n. 17
0
File: 68.cpp Progetto: cedarz/ltcode
    vector<string> fullJustify(vector<string>& words, int maxWidth) {
        int start = 0;
        int cnt = 0;
        int len = 0;
        int sz = words.size();
        if(sz == 0) return vector<string>();
        vector<string> res;
        for(int i = 0; i < sz; ++i) {
            if(cnt == 0) { 
                start = i;
            }
            
            if(cnt > 0) ++len; // one space at least
            if(len + words[i].size() <= maxWidth) {
                ++cnt;
                len += words[i].size();
                if(start + cnt == sz) {
                    goto COMBINE;
                }
            } else {
                --i;
                if(cnt > 0) --len;
                goto COMBINE;
            }
            
        
            continue;
COMBINE:
            cout << len << " : " << start << " " << cnt << endl;
            int spaces = maxWidth - len + cnt - 1;
            int div = cnt > 1 ? spaces / (cnt - 1) : spaces;
            int ram = cnt > 1 ? spaces % (cnt - 1) : 1;
        
            cout << spaces << " " << div << " / " << ram << endl;
            string just("");
            if(start + cnt == sz) {
                int last = spaces - cnt + 1;
                for(int cum = 0; cum < cnt; ++ cum) {
                    if(cum == cnt - 1) {
                        just += words[start + cum] + string(last, ' ');
                        break;
                    }
                    just += words[start + cum];
                    if(cnt > 1) {
                        just += " ";
                    }
                }
                len = 0;
                cnt = 0;
                res.push_back(just);
                break;
            }
            if(cnt == 1) {
                just += words[start] + string(div, ' ');
            } else {
            for(int cum = 0; cum < cnt; ++cum) {
                if(cum == cnt - 1) {
                    just += words[start + cum];
                    break;
                }
                if(cum < ram) {
                    just += words[start + cum] + string(div + 1, ' ');
                } else {
                    just += words[start + cum] + string(div, ' ');
                }
            }
            }
            len = 0;
            cnt = 0;
            res.push_back(just);
        }
        return res;       
    }
Esempio n. 18
0
void MonadicLawsProofing()
{
	//Scala notation: unit(x) flatMap f == f(x)
	{
		//Left Identity (1st Law)
		auto x = just(read_att48_tsp());
		
		auto f = [](TSP::T t){ return ref(t).do_cycle_length(); };

		double fun_result = bnd<double>(ret(x), f); //functional composition
		double oo_result = ret(x).map<double>(f); //object-oriented

		bool fun_holds = fun_result == f(x);
		bool oo_holds = oo_result == f(x);

		std::cout << "1st Law (Left Identity) " << (fun_holds ? "holds" : "doesn't hold") << std::endl;
		std::cout << "1st Law (Left Identity) " << (oo_holds ? "holds" : "doesn't hold") << std::endl;
	}

	//Scala notation: m flatMap unit == m
	{
		//Right Identity (2nd Law)
		auto m = make_TSP(read_att48_tsp());
		
		auto fun_result = bnd(m, ret);
		auto oo_result = m.map(ret);

		bool fun_holds = fun_result == m;
		bool oo_holds = oo_result == m;

		std::cout << "2nd Law (Right Identity) " << (fun_holds ? "holds" : "doesn't hold") << std::endl;
		std::cout << "2nd Law (Right Identity) " << (oo_holds ? "holds" : "doesn't hold") << std::endl;
	}

	//Scala notation: m flatMap f flatMap g == m flatMap (x => f(x) flatMap g)
	{
		//Associativity (3rd Law)
		auto m = make_TSP(read_att48_tsp());

		auto f = [](TSP::T t) -> TSP
		{ 
			auto u = ref(t);
			std::swap(u.cities[0], u.cities[1]);
			return make_TSP(u); 
		};
		
		auto g = [](TSP::T t) -> TSP
		{ 
			auto u = ref(t);
			std::swap(u.cities[2], u.cities[3]);
			return make_TSP(u); 
		};

		auto fun_result_1 = bnd(bnd(m, f), g);
		auto fun_result_2 = bnd(m, [&](TSP::T t) {
			return bnd(f(t), g);
		});

		auto oo_result_1 = m.map(f).map(g);
		auto oo_result_2 = m.map([&](TSP::T t) {
			return f(t).map(g);
		}); 
		
		bool fun_holds = fun_result_1 == fun_result_2;
		bool oo_holds = oo_result_1 == oo_result_2;

		std::cout << "3rd Law (Associativity) " << (fun_holds ? "holds" : "doesn't hold") << std::endl;
		std::cout << "3rd Law (Associativity) " << (oo_holds ? "holds" : "doesn't hold") << std::endl;
	}
}
Esempio n. 19
0
TSP make_TSP(const tsp_class& tsp_instance) { return TSP(just(tsp_instance)); }
Esempio n. 20
0
Maybe<CliArgParser::HelpInfo> ExtensionArgParser::helpInfo() const {
  return just(HelpInfo{"-e", "--extension", tr("ext"),
                       tr("Select target subtitles file extension")});
}
Esempio n. 21
0
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
*****************************************************************************/

#include "napisy24downloadengine.h"
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QProcess>
#include <QUrl>
#include <QUrlQuery>

SubtitleDownloadEngineMetadata Napisy24DownloadEngine::metadata =
    SubtitleDownloadEngineMetadata(
        "Napisy24",
        QObject::tr("<b>www.napisy24.pl</b> subtitle download engine"),
        just(QUrl("http://napisy24.pl/cb-registration/registers")),
        just(QUrl("http://napisy24.pl/dodaj-napisy")));

Napisy24DownloadEngine::Napisy24DownloadEngine(
    const QString &tmpPath, const EngineConfig &config,
    const QSharedPointer<const P7ZipDecoder> &p7zipDecoder,
    const QStringList &subtitleExtensions)
    : SubtitleDownloadEngine(tmpPath),
      engineConfig(config),
      p7zipDecoder(p7zipDecoder),
      subtitleExtensions(subtitleExtensions) {}

Napisy24DownloadEngine::~Napisy24DownloadEngine() { cleanup(); }

SubtitleDownloadEngineMetadata Napisy24DownloadEngine::meta() const {
  return Napisy24DownloadEngine::metadata;
Esempio n. 22
0
Maybe<CliArgParser::HelpInfo> DontShowListArgParser::helpInfo() const {
  return just(HelpInfo{"-d", "--dont-show-list", "",
                       tr("Never show a list of available subtitles")});
}
Esempio n. 23
0
void Maybe_a_pure(OPObject* _self, void* data)
{
  Maybe* self = (Maybe*) _self;
  just(self, data);
}
Esempio n. 24
0
 static constexpr auto apply(Set set, Pred p) {
     auto x = set.find(p);
     return if_(p(x), just(x), nothing);
 }
Esempio n. 25
0
int main()
{ /*  MIRACL rational calculator */
    int i,j,k,p,q,c,hpos;
    BOOL over,help;
    screen();
#if MIRACL==16
    mip=mirsys(10,0);      /*** 16-bit computer ***/
#else
    mip=mirsys(6,0);       /*** 32-bit computer ***/
#endif
    mip->ERCON=TRUE;
    x=mirvar(0);
    for (i=0;i<=top;i++) y[i]=mirvar(0);
    m=mirvar(0);
    t=mirvar(0);
    radeg=mirvar(0);
    loge2=mirvar(0);
    loge10=mirvar(0);
    eps=mirvar(0);
    mip->pi=mirvar(0);
    cinstr(mip->pi,cpi);            /* read in constants */
    fpmul(mip->pi,1,180,radeg);
    cinstr(loge2,clg2);
    cinstr(loge10,clg10);
    cinstr(eps,ceps);
    help=OFF;
    show(TRUE);
    p=6;
    q=0;
    flag=OFF;
    newx=OFF;
    over=FALSE;


    setopts();
    clrall();
    drawit();
    while (!over)
    { /* main loop */
        if (mip->ERNUM)
        {
            aprint(ORDINARY,4+5*p,6+3*q,keys[q][p]);
            p=5,q=0;
        }
        if (width==80 || !help)
        {
            aprint(INVER,4+5*p,6+3*q,keys[q][p]);
            curser(1,24);
            c=gethit();
            aprint(ORDINARY,4+5*p,6+3*q,keys[q][p]);
        }
        else while ((c=gethit())!='H') ;
        result=TRUE;
        if ((k=arrow(c))!=0)
        { /* arrow key hit */
            if (k==1 && q>0) q--;
            if (k==2 && q<5) q++;
            if (k==3 && p<6) p++;
            if (k==4 && p>0) p--;
            continue;
        }
        if (c=='H')
        { /* switch help on/off */
            help=!help;
            for (i=1;i<=24;i++)
            {
                if (width==80) hpos=41;
                else           hpos=1;
                if (help) aprint(HELPCOL,hpos,i,htext[i-1]);
                else lclr(hpos,i);
            }
            if (width==40 && !help) drawit();
            continue;
        }            
        if (c>='A' && c<='F')
        { /* hex only */
            if (!next(c)) putchar(BELL);
            else show(FALSE);
            continue;
        }
        for (j=0;j<6;j++)
            for (i=0;i<7;i++)
                if (c==qkeys[j][i]) p=i,q=j,c=' ';
        if (c==8 || c==127) p=6,q=1,c=' ';       /* aliases */
        if (c==',' || c=='a') p=5,q=5,c=' ';
        if (c=='O' || c==ESC) p=6,q=0,c=' ';
        if (c==13)  p=6,q=5,c=' ';
        if (c=='[' || c=='{') p=3,q=5,c=' ';
        if (c==']' || c=='}') p=4,q=5,c=' ';
        if (c=='d') p=5,q=2,c=' ';
        if (c=='b') p=5,q=3,c=' ';
        if (c=='^') p=3,q=2,c=' ';
        if (c==' ') over=act(p,q);
        else        continue;
        absol(x,t);
        if (fcomp(t,eps)<0) zero(x);
        if (result)
        { /* output result to display */
            cotstr(x,mip->IOBUFF);
            just((char *)mip->IOBUFF);
            if (mip->ERNUM<0)
            { /* convert to radix and try again */
                mip->ERNUM=0;
                mip->RPOINT=ON;
                cotstr(x,mip->IOBUFF);
                putchar(BELL);
                just((char *)mip->IOBUFF);
            }
            clr();
        }
        if (newx)
        { /* update display */
            getstat();
            show(FALSE);
        }
    }
    curser(1,24);
    restore();
    return 0;
}
Esempio n. 26
0
Maybe<CliArgParser::HelpInfo> ShowListArgParser::helpInfo() const {
  return just(HelpInfo{"-s", "--show-list", "",
                       tr("Always show a list of available subtitles")});
}